cURL可以下载图像,但是带有请求的python代码不起作用。如何解决?

时间:2019-05-06 08:52:42

标签: python curl python-requests

我正在尝试下载图片,它可以通过cURL正常工作。 以下是我曾经下载的cURL命令:

curl 'https://www.childrensplace.com/wcsstore/GlobalSAS/images/tcp/products/500/2625290_1305.jpg' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36' -H 'DNT: 1' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'Cookie: ROUTEID=.route11; JSESSIONID=0FACDCD11F380C39195450C619527A68' --compressed > test.jpg

当我尝试通过python请求遵循相同的流程时,我没有得到响应。 以下是用于下载同一图像的python代码:

import requests

cookies = {
    'ROUTEID': '.route11',
    'JSESSIONID': '0FACDCD11F380C39195450C619527A68',
}

headers = {
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
    'DNT': '1',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'en-US,en;q=0.9',
}

response = requests.get('https://www.childrensplace.com/wcsstore/GlobalSAS/images/tcp/products/500/2625290_1305.jpg', headers=headers, cookies=cookies)

我尝试在同一台机器上同时运行cURL和Python请求。我是否想添加一些专门用Python代码编写的内容?通过Python尝试时出现读取超时错误。

0 个答案:

没有答案