gpt4 book ai didi

python - 尝试在 python 中执行 get 请求时出现 [Errno 110] 'Connection timed out'

转载 作者:太空宇宙 更新时间:2023-11-03 14:01:11 25 4
gpt4 key购买 nike

我可以在 Firefox 浏览器中手动访问代码中提到的以下“URL”,并查看 json 响应:

{
"version" : "1.0",
"email_address" : "xxxx@emailin.com"
}

但是当我尝试使用以下代码执行获取请求时,我收到连接超时错误。

import requests
URL='https://deviceconfig.pod1.pie.avatar.ext.hp.com/virtualprinter/v1/printers/emailaddress/AQAAAAFiGLv5GQAAAAGrHfgO'
proxies = {'http': '', 'https': ''}
headers={'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'}
try:
r= requests.get(url=URL,proxies=proxies,verify=False,headers=headers)
print r.status_code
print r.content
except requests.exceptions.RequestException as e:
print e.message

Error :
HTTPSConnectionPool(host='deviceconfig.pod1.pie.avatar.ext.hp.com', port=443): Max retries exceeded with url: /virtualprinter/v1/printers/emailaddress/AQAAAAFiGLv5GQAAAAGrHfgO (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd9f45080d0>: Failed to establish a new connection: [Errno 110] Connection timed out',))

最佳答案

现在,通过使用端口号设置代理,获取请求正在工作。

在上面的代码中添加了代理设置:

proxies = { 'http': 'web-proxy.xxxxxx.xx.com:8080','https': 'web-proxy.xxxxxx.xx.com:8080'}

Output :
200
{
"version" : "1.0",
"email_address" : "xxxx@emailin.com"
}

关于python - 尝试在 python 中执行 get 请求时出现 [Errno 110] 'Connection timed out',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49234416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com