這是代碼:
requests.get('https://www.tng-project.org/api/TNG50-1/snapshots/99/subhalos/503437/cutout.hdf5', params = {'stars':'Masses'}, headers={"api-key":"7d595e082708acc270489c7c78dbcc53"})
在這里我得到結果:<Response [200]>。
但是,如果我將 替換為requests.get,requests.head如下所示:
requests.head('https://www.tng-project.org/api/TNG50-1/snapshots/99/subhalos/503437/cutout.hdf5', params = {'stars':'Masses'}, headers={"api-key":"7d595e082708acc270489c7c78dbcc53"})
我得到了 result <Response [302]>,這意味著我無法從此命令列獲取任何有意義的資訊。
相同的代碼怎么能requests.get給出requests.head不同的結果呢?
我有可能得到<Response [200]>嗎requests.head?因為我想在不下載檔案的情況下閱讀標題。
uj5u.com熱心網友回復:
默認情況下requests遵循重定向,但requests.head特別不:
requests.head
**kwargs– 請求采用的可選引數。如果allow_redirects未提供,它將被設定為False(與默認請求行為相反)。https://docs.python-requests.org/en/latest/api/#requests.head
所以,要么弄清楚是否有一個規范的 URL,你可以直接點擊而無需重定向,或者通過allow_redirects=True.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/418614.html
標籤:
上一篇:如何從我的網站禁用或洗掉網頁
