Python 请求方法没有响应
Python requests method is not responsing
我想向请求库中 python 上的网站发送 GET 请求,但超时了。当我在 linux bash 中发送 Get 请求(使用 wget)时,它正在响应。
正在 python:
import requests as req
url = 'https://mkyong.com/computer-tips/how-to-view-http-headers-in-google-chrome/'
content = req.get(url, timeout=30)
print(content)
这不适用于 python(我想使用此页面):
import requests as req
url = 'https://sahibinden.com/'
content = req.get(url, timeout=30)
print(content)
这是在 wget 上工作:
[input]
emr@DESKTOP-05BO8UL:~$ wget sahibinden.com
[output]
--2021-09-30 22:09:20-- http://sahibinden.com/
Resolving sahibinden.com (sahibinden.com)... 85.111.30.111
Connecting to sahibinden.com (sahibinden.com)|85.111.30.111|:80... connected.
HTTP request sent, awaiting response... 301 MOVED PERMANENTLY
Location: https://sahibinden.com/ [following]
--2021-09-30 22:09:20-- https://sahibinden.com/
Connecting to sahibinden.com (sahibinden.com)|85.111.30.111|:443... connected.
HTTP request sent, awaiting response... 301 MOVED PERMANENTLY
Location: https://www.sahibinden.com/ [following]
--2021-09-30 22:09:20-- https://www.sahibinden.com/
Resolving www.sahibinden.com (www.sahibinden.com)... 85.153.138.111
Connecting to www.sahibinden.com (www.sahibinden.com)|85.153.138.111|:443... connected.
HTTP request sent, awaiting response... 200
Length: unspecified [text/html]
Saving to: ‘index.html’
index.html [ <=> ] 200.88K --.-KB/s in 0.1s
2021-09-30 22:09:21 (1.31 MB/s) - ‘index.html’ saved [205699]
您可能需要提供用户代理。
import requests as req
url = 'https://sahibinden.com/'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
content = req.get(url, headers=headers, timeout=6)
print(content)
该特定服务器似乎因请求而超载,因此可能无法return任何有意义的事情。
我想向请求库中 python 上的网站发送 GET 请求,但超时了。当我在 linux bash 中发送 Get 请求(使用 wget)时,它正在响应。
正在 python:
import requests as req
url = 'https://mkyong.com/computer-tips/how-to-view-http-headers-in-google-chrome/'
content = req.get(url, timeout=30)
print(content)
这不适用于 python(我想使用此页面):
import requests as req
url = 'https://sahibinden.com/'
content = req.get(url, timeout=30)
print(content)
这是在 wget 上工作:
[input]
emr@DESKTOP-05BO8UL:~$ wget sahibinden.com
[output]
--2021-09-30 22:09:20-- http://sahibinden.com/
Resolving sahibinden.com (sahibinden.com)... 85.111.30.111
Connecting to sahibinden.com (sahibinden.com)|85.111.30.111|:80... connected.
HTTP request sent, awaiting response... 301 MOVED PERMANENTLY
Location: https://sahibinden.com/ [following]
--2021-09-30 22:09:20-- https://sahibinden.com/
Connecting to sahibinden.com (sahibinden.com)|85.111.30.111|:443... connected.
HTTP request sent, awaiting response... 301 MOVED PERMANENTLY
Location: https://www.sahibinden.com/ [following]
--2021-09-30 22:09:20-- https://www.sahibinden.com/
Resolving www.sahibinden.com (www.sahibinden.com)... 85.153.138.111
Connecting to www.sahibinden.com (www.sahibinden.com)|85.153.138.111|:443... connected.
HTTP request sent, awaiting response... 200
Length: unspecified [text/html]
Saving to: ‘index.html’
index.html [ <=> ] 200.88K --.-KB/s in 0.1s
2021-09-30 22:09:21 (1.31 MB/s) - ‘index.html’ saved [205699]
您可能需要提供用户代理。
import requests as req
url = 'https://sahibinden.com/'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
content = req.get(url, headers=headers, timeout=6)
print(content)
该特定服务器似乎因请求而超载,因此可能无法return任何有意义的事情。