Python错误:TypeError:getsockaddrarg:AF_INET地址必须是元组,而不是int

Posted

技术标签:

【中文标题】Python错误:TypeError:getsockaddrarg:AF_INET地址必须是元组,而不是int【英文标题】:Python error: TypeError: getsockaddrarg: AF_INET address must be tuple, not int 【发布时间】:2015-11-04 11:16:42 【问题描述】:

当我启动我的程序时:

import bitcoinrpc
import csv

# docs at https://github.com/massanchik/bitcoin-python3
# docs at https://docs.python.org/3.3/library/csv.html


user = 'user'
password = 'password'
port = '44555'
host='127.0.0.1'

access = bitcoinrpc.connect_to_remote(user, password, host, port)

print(access.getinfo())

我收到以下错误:

Traceback (most recent call last):
  File "electrum_to_clam.py", line 14, in <module>
    print(access.getinfo())
  File "/usr/local/lib/python3.4/dist-packages/bitcoinrpc/connection.py", line 133, in getinfo
    return ServerInfo(**self.proxy.getinfo())
  File "/usr/local/lib/python3.4/dist-packages/bitcoinrpc/proxy.py", line 116, in __call__
    resp = self._service_proxy._transport.request(postdata)
  File "/usr/local/lib/python3.4/dist-packages/bitcoinrpc/proxy.py", line 67, in request
    'Content-type': 'application/json')
  File "/usr/lib/python3.4/http/client.py", line 1065, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1103, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1061, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 906, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 841, in send
    self.connect()
  File "/usr/lib/python3.4/http/client.py", line 819, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python3.4/socket.py", line 499, in create_connection
    sock.bind(source_address)
TypeError: getsockaddrarg: AF_INET address must be tuple, not int

可能是什么原因,我该如何解决?

【问题讨论】:

我有同样的错误,使用变量端口作为 int 并不能解决问题。 Python3.4 【参考方案1】:

Nhor 刚刚写的,port 应该是这里提到的 int

https://laanwj.github.io/bitcoin-python/doc/bitcoinrpc.html

bitcoinrpc.connect_to_remote(user, password, host='localhost', port=8332, use_https=False)

【讨论】:

404 链接到 github 页面。【参考方案2】:

您的端口必须是int,而不是str。使用:

port = 44555

【讨论】:

【参考方案3】:

元组就像 (a, b, c ....)。 参数应该是一个元组,然后试试这个:

access = bitcoinrpc.connect_to_remote((user, password, host, port))

或其他方式

con_data = (user, password, host, port)
access = bitcoinrpc.connect_to_remote(con_data)

【讨论】:

以上是关于Python错误:TypeError:getsockaddrarg:AF_INET地址必须是元组,而不是int的主要内容,如果未能解决你的问题,请参考以下文章

Python:Concurrent.Futures 错误 [TypeError:'NoneType' 对象不可调用]

python TypeError: must be str, not bytes错误

代码错误Python:TypeError:/:'set'和'int'不支持的操作数类型

Python 错误:TypeError:'Timestamp' 类型的对象不是 JSON 可序列化的'

Python错误TypeError: write() argument must be str, not bytes

python numpy错误“TypeError:'numpy.float64'对象不能解释为整数”