Skip to content

[已解決][Linux] 使用 wget 得到 302 Found 但是無法成功下載檔案

我之前有在 GitHub 上分享一個使用 Python 透過字型檔產生圖片的專案,在我專案的範例中,我使用了 wget 指令來下載一個開源的字型。

然而在兩年後的今天,當我在整理專案時,我發現其無法成功下載。

wget https://www.1001freefonts.com/d/26673/atozimple.zip


Output:

--2022-07-25 15:54:00--  https://www.1001freefonts.com/d/26673/atozimple.zip
Resolving www.1001freefonts.com (www.1001freefonts.com)... 172.66.43.121, 172.66.40.135, 2606:4700:3108::ac42:2b79, ...
Connecting to www.1001freefonts.com (www.1001freefonts.com)|172.66.43.121|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: /atozimple.font [following]
--2022-07-25 15:54:00--  https://www.1001freefonts.com/atozimple.font
Reusing existing connection to www.1001freefonts.com:443.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘atozimple.zip’

atozimple.zip               [ <=>                          ]  53.69K  --.-KB/s    in 0.007s  

2022-07-25 15:54:01 (7.40 MB/s) - ‘atozimple.zip’ saved [54982]


這樣下載的檔案是失敗的,僅有少少幾 kb。一開始我以為是連結壞了、網站搬家等問題,但是當我又去網站查看了之後,我發現網站照常運行、而且連結甚至跟之前一模一樣。

我在實際瀏覽器確認後,發現會重導向回網站。

解決方法為:

wget https://www.1001freefonts.com/d/26673/atozimple.zip --referer=https://www.1001freefonts.com/


HTTP Referer 通常為指示請求的來源地址,有可能是為了阻止不正常的請求或攻擊所以網站的管理者會檢查 Referer 標題。所以當我們在 wget 指令中添加了 –referer 參數,實際上正是用來模擬瀏覽器的操作。

我有查詢到這個解決方法,但以上的說明為 GPT-4 所告知,可以作為參考但仍需驗證。


References


Read More

Tags:

Leave a Reply