OSError: [Errno 22] Invalid argument: 'protocol'

改为这样不报错,但是报别的错:

def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
        # For user code address family and type values are IntEnum members, but
        # for the underlying _socket.socket they're just integers. The
        # constructor of _socket.socket converts the given argument to an
        # integer automatically.
        proto=int(proto)
        if fileno is None:
            if family == -1:
                family = AF_INET
            if type == -1:
                type = SOCK_STREAM
        if proto == -1:
            proto = 0
        print("111111111111",family, type, proto, fileno)
        _socket.socket.__init__(self, family, type, proto, fileno)
        self._io_refs = 0
        self._closed = False

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/python3.7.5/lib/python3.7/multiprocessing/forkserver.py", line 186, in main
    with socket.socket(socket.AF_UNIX, fileno=listener_fd) as listener, \
  File "/usr/local/python3.7.5/lib/python3.7/socket.py", line 151, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
OSError: [Errno 22] Invalid argument: 'protocol'

  1. 先写上代码:

    import time

    date = '1583424688064'
    timeArray=time.localtime(int(date))
    print(time.strftime("%Y-%m-%d", timeArray))

    此时运行就会出现错误:OSError: [Errno 22] Invalid argument

  2. 错误的原因不在于格式,因为我们已通过int(date)进行了转换,真正的错误在于date的长度,一般爬取下来时显示的时间戳时长都是13位的数字,而time.localtime的参数要的长度是10位,所以我们需要将其/1000并取整即可。

  3. import time

    date = '1583424688064'
    timeArray=time.localtime(int(int(date)/1000))
    print(time.strftime("%Y-%m-%d", timeArray))

    此时就能得到2020-03-06这样的格式了。

要使用socket.socket()函数来创建套接字。其语法如下:

socket.socket(socket_family,socket_type,protocol=0)

socket_family可以是如下参数:

  socket.AF_INET IPv4(默认)

  socket.AF_INET6 IPv6

  socket.AF_UNIX 只能够用于单一的Unix系统进程间通信

socket_type可以是如下参数:

  socket.SOCK_STREAM  流式socket , for TCP (默认)

  socket.SOCK_DGRAM   数据报式socket , for UDP

  socket.SOCK_RAW 原始套接字,普通的套接字无法处理ICMP、IGMP等网络报文,而SOCK_RAW可以;其次,SOCK_RAW也可以处理特殊的IPv4报文;此外,利用原始套接字,可以通过IP_HDRINCL套接字选项由用户构造IP头。

  socket.SOCK_RDM 是一种可靠的UDP形式,即保证交付数据报但不保证顺序。SOCK_RAM用来提供对原始协议的低级访问,在需要执行某些特殊操作时使用,如发送ICMP报文。SOCK_RAM通常仅限于高级用户或管理员运行的程序使用。

  socket.SOCK_SEQPACKET 可靠的连续数据包服务

protocol参数:

  0  (默认)与特定的地址家族相关的协议,如果是 0 ,则系统就会根据地址格式和套接类别,自动选择一个合适的协议

昇腾 OSError: [Errno 22] Invalid argument: ‘protocol‘相关推荐

  1. 成功解决fp = builtins.open(filename, quot;rbquot;) OSError: [Errno 22] Invalid argument: 'F:\\File_Pyt

    成功解决fp = builtins.open(filename, "rb") OSError: [Errno 22] Invalid argument: 'F:\\File_Pyt ...

  2. tensorboard出现OSError: [Errno 22] Invalid argument问题解决

    tensorboard出现OSError: [Errno 22] Invalid argument问题解决 问题描述 使用tensorboard的时候提示错误: W0308 10:12:12.6217 ...

  3. 在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: ‘文件路径’

    如题,在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: '文件路径',在查阅了大量资料后也得到了一些解决方案,但是这些解决方案 ...

  4. OSError: [Errno 22] Invalid argument:**

    OSError: [Errno 22] Invalid argument: 在使用open打开文件时,出现报错 OSError: [Errno 22] Invalid argument: 'H:\\G ...

  5. Python OSError: [Errno 22] Invalid argument:的出现和解决

    1.在学习从文件读取数据中,写了个示例代码,读取不在同一个目录的file.txt,运行后报这个Python OSError: [Errno 22] Invalid argument:错误: (1).首 ...

  6. OSError: [Errno 22] Invalid argument: ‘C:\\Users\\0moyi0\\Desktop\\AD_kk.png‘

    报错代码 #-*-coding:GBK -*- from PIL import Imagefilename = r"C:\Users\0moyi0\Desktop\AD.png" ...

  7. python中遇到报错OSError: [Errno 22] Invalid argument的解决方法

    将时间戳用python语言转换成指定日期: 代码如下: import timetimeStamp = 1589018284000 timeArray = time.localtime(timeStam ...

  8. 【报错】“OSError: [Errno 22] Invalid argument: ‘cache\\resume_lattice_only_tra”

    [报错]"OSError: [Errno 22] Invalid argument: 'cache\resume_lattice_only_train:" Windows上运行Fl ...

  9. pyLDAvis3.3.1 报错 OSError: [Errno 22] Invalid argument: ‘https://cdn.jsdelivr.net/gh/bmabey/pyLDAvis@

    问题描述: pyLDAvis3.3.1 报错: File "E:\ProgramData\Anaconda3\lib\site-packages\pyLDAvis_display.py&qu ...

最新文章

  1. 指定服务器无效,安装sqlserver2008r2 服务器配置,服务帐户配置出错,提示Sql server服务指定的凭据无效...
  2. 系统吞吐量(TPS)、用户并发量、性能测试概念和公式(转载)
  3. ERP系统管理员的工具箱 推荐几款优秀的数据比较同步工具 Data Compare and Sync tool...
  4. Web.config配置访问权限
  5. php中unset函数是在哪一章_PHP unset函数原理及使用方法解析
  6. Python 数据处理函数 round()、int()、floor()、ceil()的用法
  7. Bootstrap 的辅助类
  8. android的opencv调试,Android opencv 2.3.1 调试及应用(第一篇)
  9. 《云数据中心构建实战:核心技术、运维管理、安全与高可用》——2.4 云计算的发展历程与未来趋势...
  10. javafx弹出二级stage窗口时虚化主窗口
  11. Win10黑屏的时候显示时钟怎么设置
  12. 基于DWM1000模块开发UWB系统进行室内定位
  13. 判断单链表是否中心对称算法
  14. 留一份名单,以供研究:2009中国企业500强全名单
  15. Javaweb支付宝支付
  16. 解决Waiting for incoming connection with ide key xdebug错误
  17. 高斯型随机粗糙面MATLAB仿真
  18. laravel-admin多图上传小技巧
  19. 可达性分析算法与强弱引用
  20. 现代密码学-密码学概论与基本知识

热门文章

  1. Windows驱动中的Crash回调
  2. CentOS 7.2搭建NFS并使用
  3. OpenStack-MitakaCentos7.2双节点搭建--(三)Glance(镜像服务)
  4. android 8.1 go,Android 8.1 Settings 的热点源码分析-Go语言中文社区
  5. 计算机组成原理考试知识点总结,最新2018计算机组成原理期末复习考试知识点复习考点归纳总结总结...
  6. 程序员的杂想-不要只做一名程序员
  7. Linux内核网络丢包查看工具dropwatch的安装和使用
  8. 嵌入式c语言汇编混合编程,嵌入式C语言和汇编语言的混合编程
  9. java 搜索业务怎么写_Java项目实战第11天:搜索功能的实现
  10. 三维重建_快速分类–三向和双枢轴