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'
-
先写上代码:
import time
date = '1583424688064'
timeArray=time.localtime(int(date))
print(time.strftime("%Y-%m-%d", timeArray))此时运行就会出现错误:OSError: [Errno 22] Invalid argument
-
错误的原因不在于格式,因为我们已通过int(date)进行了转换,真正的错误在于date的长度,一般爬取下来时显示的时间戳时长都是13位的数字,而time.localtime的参数要的长度是10位,所以我们需要将其/1000并取整即可。
-
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 ,则系统就会根据地址格式和套接类别,自动选择一个合适的协议