簡體   English   中英

為什么這個網站的請求模塊隨機失敗

[英]why does the requests module fail at random with this website

I'm using python to download some audio tracks from archive.org, here is one example of a link: http://archive.org/32/items/goblinmarket_etk_librivox/goblinmarket_01_rossetti_64kb.mp3 In the browser this redirects to: https:/ /ia801601.us.archive.org/32/items/goblinmarket_etk_librivox/goblinmarket_01_rossetti_64kb.mp3在我的應用程序中,我使用以下代碼:

headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', 'Accept':'*/*'}
v=requests.get(what[0], stream=True, allow_redirects=True, headers=headers)

有時這會按預期工作(這很好。)其他時候雖然它會掛起一段時間,然后引發一個錯誤,該錯誤與 url 超出的最大重試次數有關。

誰能指出我正確的方向來解決這個問題? 瀏覽器加載它沒有問題。 附加信息:通常它在第一次嘗試時會失敗,但之后會無動於衷。

對於將來遇到這種情況的任何人,按照發布的評論(對此我非常感激),我查看並添加了接受語言、升級不安全請求、接受編碼和最大緩存標頭。 其中之一(不太確定是哪一個),但其中之一解決了問題。

感謝大家。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM