httplib2 使用代理给出内部服务器错误 500

发布于 2024-09-03 01:59:41 字数 1833 浏览 5 评论 0原文

以下是它抛出的代码和错误。它在没有代理 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')

Following is the code and error it throws. It works fine without the proxy http = httplib2.Http() .

When I try the same http proxy in Firefox, it works fine.

Any pointers are highly appreciated!

Usage :

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')

Error :

  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')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初相遇 2024-09-10 01:59:41

确保代理不透明。我对此不太了解,但显然透明代理使服务器能够看到您正在使用代理,甚至可能访问您的 IP。有些网站肯定会关闭任何看似来自代理的请求(因为担心机器人)。这可能意味着抛出假的内部服务器错误或实际遇到错误。对我来说,使用匿名代理总是可以解决这个问题。既然你说它不需要代理就可以工作,所以我会从那里开始。

Make sure the proxy isn't transparent. I don't know too much about this, but evidently a transparent proxy enables the server to see you're using a proxy, and perhaps even access your IP. Some websites will definitely shut down any requests that appear to originate from a proxy (for fear of bots). That may mean either throwing a fake internal server error or actually encountering an error. For me, using an anonymous proxy has always solved that problem. Since you said it works without the proxy, I would start there.

舞袖。长 2024-09-10 01:59:41

SOCKS 客户端库是否已安装并可用于您的代码?仅当安装了 SOCKS 库时,代理支持才起作用。

Is the SOCKS client library installed and available to your code? The proxy support only works if the SOCKS library is installed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文