簡體   English   中英

無法使用 requests.get() 從 Reddit 提交圖像 URL

[英]Trouble submitting image URL from Reddit using requests.get()

我正在嘗試使用 Python 中的requests.get()從 Reddit.com 將圖像 URL 提交到願景 API 但我遇到了困難,這可能是我的一個簡單錯誤。 當鏈接指向明確的 *.jpg 時, requests.get()請求成功,例如https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Beef_fillet_steak_with_mushrooms.jpg/800px-Beef_fillet_steak_with_mushrooms.jpg ,但當鏈接指向我認為是軟鏈接的內容時不成功,例如https://preview.redd.it/9xu97c5snpr51.jpg?width=640&crop=smart&auto=webp&s=e68c02166f6fd21a47a957b187b98b92608f54a9 請注意,當粘貼到瀏覽器中時,兩個鏈接都可以正常工作。

有沒有人建議我如何預處理第二個鏈接,以便像第一個鏈接一樣處理它? 我希望最終可以遠程運行此代碼,因此最好避免在本地下載文件。

來自以下文檔: https://requests.readthedocs.io/en/master/user/quickstart/

對於非文本請求,您可以以字節形式訪問響應主體:

from PIL import Image
from io import BytesIO

i = Image.open(BytesIO(r.content))

暫無
暫無

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

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