【发布时间】:2020-11-08 10:06:48
【问题描述】:
我试图在 python 中创建一个特定的 GET 请求到该站点: https://sgfm.elcorteingles.es/SGFM/dctm/MEDIA03/202006/24/00117731276964____5__210x210.jpg
但是我没有得到浏览器的任何响应,它一直在等待。 然后我尝试创建一个 curl 请求并发生同样的事情(一直等待)。 毕竟,我尝试创建一个 POSTMAN 请求,并且效果很好!而且我不明白为什么它适用于邮递员,但不适用于 python 和 curl,因为所有这些平台都不像浏览器。 我使用postman方法将postman请求转换为python和curl:
#python
import requests
url = "https://sgfm.elcorteingles.es/SGFM/dctm/MEDIA03/202006/24/00117731276964____5__210x210.jpg"
payload = {}
headers= {}
response = requests.request("GET", url, headers=headers, json = payload)
print(response.text.encode('utf8'))
#curl
curl --location --request GET 'https://sgfm.elcorteingles.es/SGFM/dctm/MEDIA03/202006/24/00117731276964____5__210x210.jpg'
但他们都没有得到任何回应。 有谁知道为什么会发生这种情况并将其转换为 python 请求?甚至 curl 我也可以处理。
【问题讨论】:
-
你必须使用
requests.get(url, ...)而不是requests.request() -
网站/服务器正在阻止来自 curl/requests 等客户端的调用。
-
@FishingCode 使用 .get() 而不是 .request("url", ...) 有什么区别?
标签: python curl python-requests postman urllib