以下是它抛出的代码和错误。没有代理http = httplib2.Http()
,它工作正常。
当我在Firefox中尝试使用相同的http代理时,它可以正常工作。
任何指针都非常感谢!
用法:
http = httplib2.Http(proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, '68.48.25.158', 25681))
main_url = 'http://www.mywebsite.com'
response, content = http.request(main_url, 'GET')
错误:
File "testproxy.py", line 17, in <module>
response, content = http.request(main_url, 'GET')
File "/home/kk/bin/pythonlib/httplib2/__init__.py", line 1129, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/home/kk/bin/pythonlib/httplib2/__init__.py", line 901, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/home/kk/bin/pythonlib/httplib2/__init__.py", line 862, in _conn_request
conn.request(method, request_uri, body, headers)
File "/usr/lib/python2.5/httplib.py", line 866, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.5/httplib.py", line 889, in _send_request
self.endheaders()
File "/usr/lib/python2.5/httplib.py", line 860, in endheaders
self._send_output()
File "/usr/lib/python2.5/httplib.py", line 732, in _send_output
self.send(msg)
File "/usr/lib/python2.5/httplib.py", line 699, in send
self.connect()
File "/home/kk/bin/pythonlib/httplib2/__init__.py", line 740, in connect
self.sock.connect(sa)
File "/home/kk/bin/pythonlib/socks.py", line 383, in connect
self.__negotiatehttp(destpair[0],destpair[1])
File "/home/kk/bin/pythonlib/socks.py", line 349, in __negotiatehttp
raise HTTPError((statuscode,statusline[2]))
socks.HTTPError: (500, 'Internal Server Error')
答案 0 :(得分:1)
确保代理不透明。我对此并不太了解,但显然透明代理使服务器能够看到您正在使用代理,甚至可能访问您的IP。有些网站肯定会关闭任何看似来自代理的请求(因为害怕机器人)。这可能意味着抛出虚假的内部服务器错误或实际遇到错误。对我来说,使用匿名代理始终解决了这个问题。既然你说它没有代理就行,我会从那里开始。
答案 1 :(得分:0)
SOCKS client library是否已安装并可用于您的代码?代理支持仅在安装SOCKS库时有效。