Python SocksiPy package error: TypeError: Type str doesn't support the buffer API for string?
Python SocksiPy package error: TypeError: Type str doesn't support the buffer API for string?
当我尝试通过此代码连接到 gmail 时:
import socks
import imaplib
import socket
import socks
s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_HTTP, '192.168.208.51', 3128)
s.connect(('imap.gmail.com', 993))
我收到错误消息:
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
s.connect(('imap.gmail.com', 993))
File "C:\Python34\lib\site-packages\socks.py", line 406, in connect
self.__negotiatehttp(destpair[0],destpair[1])
File "C:\Python34\lib\site-packages\socks.py", line 357, in __negotiatehttp
while resp.find("\r\n\r\n")==-1:
TypeError: Type str doesn't support the buffer API
有什么想法吗?我在使用代理的计算机上,因此使用 SocksiPy 连接到 imap.gmail.com
你的代码没有问题;您使用的 SocksiPy 版本尚未移植到 Python 3. 您应该升级到 1.02 版。或者你应该切换回 Python 2.
解释:
这是Python3。与Python2不同,bytes
和str
对象不可互换。如果你尝试做这样的事情:
>>> b'abc'.find('a')
您将看到您看到的错误。事实上,"buffer API" 是由 bytes
个对象实现的。
当我尝试通过此代码连接到 gmail 时:
import socks
import imaplib
import socket
import socks
s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_HTTP, '192.168.208.51', 3128)
s.connect(('imap.gmail.com', 993))
我收到错误消息:
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
s.connect(('imap.gmail.com', 993))
File "C:\Python34\lib\site-packages\socks.py", line 406, in connect
self.__negotiatehttp(destpair[0],destpair[1])
File "C:\Python34\lib\site-packages\socks.py", line 357, in __negotiatehttp
while resp.find("\r\n\r\n")==-1:
TypeError: Type str doesn't support the buffer API
有什么想法吗?我在使用代理的计算机上,因此使用 SocksiPy 连接到 imap.gmail.com
你的代码没有问题;您使用的 SocksiPy 版本尚未移植到 Python 3. 您应该升级到 1.02 版。或者你应该切换回 Python 2.
解释:
这是Python3。与Python2不同,bytes
和str
对象不可互换。如果你尝试做这样的事情:
>>> b'abc'.find('a')
您将看到您看到的错误。事实上,"buffer API" 是由 bytes
个对象实现的。