Python 请求挂起,而 CURL 则不会(相同的请求)

2al*_*034 5 curl http python-requests

当我尝试使用访问特定站点的请求读取响应时,我遇到了永久性的挂起,很可能是由于某种阻塞。我不确定的是,成功接收响应的 CURL 与从未接收到任何响应的 Python get 请求有何不同。

注意:curl 命令预计会返回错误,因为我没有发送 cookies 等所需信息curl:

curl 'https://www.yellowpages.com.au/search/listings?clue=Programmer&locationClue=All+States&pageNumber=3&referredBy=UNKNOWN&&eventType=pagination' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0'
Run Code Online (Sandbox Code Playgroud)

成功得到响应

Python:

import requests
r = requests.get('https://www.yellowpages.com.au/search/listings?clue=Programmer&locationClue=All+States&pageNumber=3&referredBy=UNKNOWN&&eventType=pagination', headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0'})
Run Code Online (Sandbox Code Playgroud)

永远挂在读取上

Yuu*_*Yuu 0

它适用于 python 3。

import requests
r = requests.get('https://www.yellowpages.com.au/search/listings?clue=Programmer&locationClue=All+States&pageNumber=3&referredBy=UNKNOWN&&eventType=pagination', headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0'})
print(r.headers)
Run Code Online (Sandbox Code Playgroud)

回复:

{'Cache-Control': 'max-age=86400, public', 'Content-Encoding': 'gzip', 'Content-Language': 'en-US', 'Content-Type': 'text/html;charset=utf-8', 'Server': 'Apache-Coyote/1.1', 'Vary': 'Accept-Encoding', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Length': '8009', 'Date': 'Wed, 19 Feb 2020 06:04:55 GMT', 'Connection': 'keep-alive'}
Run Code Online (Sandbox Code Playgroud)