lby*_*lby 4 python curl urllib python-requests postman
我尝试在 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'))
Run Code Online (Sandbox Code Playgroud)
#curl
curl --location --request GET 'https://sgfm.elcorteingles.es/SGFM/dctm/MEDIA03/202006/24/00117731276964____5__210x210.jpg'
Run Code Online (Sandbox Code Playgroud)
但他们都没有得到任何回应。有谁知道为什么会发生这种情况并将其转换为 python 请求?甚至卷曲我也可以处理。
Ale*_*eiw 11
服务器不接受您的标头。我尝试过这些,它对我有用。
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36', "Upgrade-Insecure-Requests": "1","DNT": "1","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language": "en-US,en;q=0.5","Accept-Encoding": "gzip, deflate"}
Run Code Online (Sandbox Code Playgroud)
此外,您需要更改您提出的请求,因为这requests.requests('GET')不是提出GET请求的正确方式。正确的一个是requests.get(url). 它们是相同的方法,但为了更清晰的代码,您应该坚持使用requests.get(url)
import requests
url = "https://sgfm.elcorteingles.es/SGFM/dctm/MEDIA03/202006/24/00117731276964____5__210x210.jpg"
payload = {}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36', "Upgrade-Insecure-Requests": "1","DNT": "1","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language": "en-US,en;q=0.5","Accept-Encoding": "gzip, deflate"}
response = requests.get(url, headers=headers)
print(response.text.encode('utf8'))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12490 次 |
| 最近记录: |