蟒蛇"TypeError: getsockaddrarg: AF_INET address must be tuple, not str"


connection = httplib.HTTPConnection('my.domain.com', port=80, strict=False,  
                                  timeout=10, source_address='9.9.9.9:666')

TypeError: getsockaddrarg: AF_INET address must be tuple, not str

我做错了什么?我只是看不到它,也找不到例子。

正在尝试使用网络地址转换编写类似路由器的模拟,因此需要添加包含端口号的发送方地址(即使我从上面的source_address中删除端口号,我仍然会收到相同的错误)。

可选的 source_address 参数可以是 (主机、端口) 的元组,用作建立 HTTP 连接的源地址。文档从这里开始。尝试使用

connection = httplib.HTTPConnection('my.domain.com', port=80, strict=False,  
                                  timeout=10, source_address=('9.9.9.9',666))

相关内容

最新更新