请求库的Python代理错误

编程入门 行业动态 更新时间:2024-10-12 20:28:15
本文介绍了请求库的Python代理错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图通过Python中的代理服务器访问Web。我正在使用请求库,我在验证我的代理时遇到问题,因为我使用的代理需要密码。

I am trying to access the web via a proxy server in Python. I am using the requests library and I am having an issue with authenticating my proxy as the proxy I am using requires a password.

proxyDict = { 'http' : 'username:mypassword@77.75.105.165', 'https' : 'username:mypassword@77.75.105.165' } r = requests.get("www.google", proxies=proxyDict)

我正在获取以下错误:

Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> r = requests.get("www.google", proxies=proxyDict) File "C:\Python27\lib\site-packages\requests\api.py", line 78, in get :param url: URL for the new :class:`Request` object. File "C:\Python27\lib\site-packages\requests\api.py", line 65, in request """Sends a POST request. Returns :class:`Response` object. File "C:\Python27\lib\site-packages\requests\sessions.py", line 187, in request def head(self, url, **kwargs): File "C:\Python27\lib\site-packages\requests\models.py", line 407, in send """ File "C:\Python27\lib\site-packages\requests\packages\urllib3\poolmanager.py", line 127, in proxy_from_url File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 521, in connection_from_url File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 497, in get_host ValueError: invalid literal for int() with base 10: 'h6f2v6jh5dsxa@77.75.105.165'

如何解决这个问题?

预先感谢您的帮助。

推荐答案

您应该从 proxyDict 中删除​​嵌入的用户名和密码,并使用 auth 参数相反。

You should remove the embedded username and password from proxyDict, and use the auth parameter instead.

import requests from requests.auth import HTTPProxyAuth proxyDict = { 'http' : '77.75.105.165', 'https' : '77.75.105.165' } auth = HTTPProxyAuth('username', 'mypassword') r = requests.get("www.google", proxies=proxyDict, auth=auth)

更多推荐

请求库的Python代理错误

本文发布于:2023-10-10 21:29:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!