[英]python requests/urllib3 connection pooling not catching HTTP errors
[英]Python: urllib3 errors where requests works
我有以下代码
http = urllib3.PoolManager()
resp = http.request(
"GET",
"https://api.nhs.uk/medicines/aciclovir",
headers={
"subscription-key":"XXX"
}
)
print(resp.data)
回应是:
You don't have permission to access "http://api.nhs.uk/medicines/aciclovir" on this server
为什么它去了http://
地址?
但是,当我使用如下请求时,它是成功的
url = "https://api.nhs.uk/medicines/aciclovir"
payload={}
headers = {
'subscription-key': 'XXX'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
有什么建议么?
更新 1
这是为发生错误而执行的确切代码,是的,它确实显示了http://
错误
更新 2
urllib3
Listening on 0.0.0.0 7777
Connection received on *** 50054
GET / HTTP/1.1
Host: ***:7777
Accept-Encoding: identity
subscription-key: xxx
User-Agent: python-urllib3/1.26.9
要求
Listening on 0.0.0.0 7777
Connection received on *** 50095
GET / HTTP/1.1
Host: ***:7777
User-Agent: python-requests/2.28.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
subscription-key: xxx
感谢https://stackoverflow.com/users/240443/amadan ,问题是服务器不喜欢 urllib3 提供的默认用户代理字符串
更改它甚至只是分解python-urllib
字符串(例如pyXthon-urllib
)使其工作
我在他们的支持下接受了这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.