使用的语句是
```python
page = requests.get( url , headers = self.header, timeout = 10 , verify = flag )
```
各变量的值分别为
```python
url = '
http://www.sbacn.org'
flag = False
self.header = {
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:40.0) Gecko/20100101 Firefox/40.0',
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' : 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding' : 'gzip, deflate',
}
```
报错内容为
```python
Traceback (most recent call last):
File "
bing.py", line 237, in <module>
bing.titleGet(urls)
File "
bing.py", line 195, in titleGet
page = self.dataRequest(url)
File "
bing.py", line 86, in dataRequest
page = requests.get( url , headers = self.header, timeout = 10 , verify = flag )
File "/usr/lib/python2.7/site-packages/requests/
api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/
api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/
sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/site-packages/requests/
sessions.py", line 608, in send
r.content
File "/usr/lib/python2.7/site-packages/requests/
models.py", line 734, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "/usr/lib/python2.7/site-packages/requests/
models.py", line 657, in generate
for chunk in
self.raw.stream(chunk_size, decode_content=True):
File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/
response.py", line 326, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/
response.py", line 282, in read
data = self._fp.read(amt)
File "/usr/lib64/python2.7/
httplib.py", line 567, in read
s = self.fp.read(amt)
File "/usr/lib64/python2.7/
socket.py", line 380, in read
data = self._sock.recv(left)
socket.error: [Errno 104] Connection reset by peer
```
我纳闷的是在我的 mac 上运行就没问题,但在服务器的 ubuntu 上运行就会报错,这是为什么?
而且我其实是抓了 bing 的搜索结果里 10 页的 url,连续访问的时候就会报错,但我要是把这个 url 单独拿出来访问的时候就没问题.这是为什么?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/234946
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.