<p>Windows在结尾('\n')添加了一个“换行”字符,这与unix Windows=CRLF不同。我在读一个Windows ASCII文本文件时遇到了类似的问题。如果我只是将文件读入列表并打印出来,它会在两者之间添加一个空行。这给了我一个线索。我使用的是建立在urllib3之上的请求库。</p>
<p>如果我用</p>
<pre><code>r = requests.get(url.strip('\n'))
</code></pre>
<p>它工作得很好。</p>
<pre><code>r = requests.get(url)
</code></pre>
<p>误炸</p>
<blockquote>
<p>Traceback (most recent call last): File
"C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.p
y", line 516, in urlopen
body=body, headers=headers) File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.p
y", line 308, in _make_request
conn.request(method, url, **httplib_request_kw) File "C:\Python34\lib\http\client.py", line 1090, in request
self._send_request(method, url, body, headers) File "C:\Python34\lib\http\client.py", line 1128, in _send_request
self.endheaders(body) File "C:\Python34\lib\http\client.py", line 1086, in endheaders
self._send_output(message_body) File "C:\Python34\lib\http\client.py", line 924, in _send_output
self.send(msg) File "C:\Python34\lib\http\client.py", line 859, in send
self.connect() File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py",
line 146, in connect
conn = self._new_conn() File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py",
line 125, in _new_conn
(self.host, self.port), self.timeout, **extra_kw) File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\connection.
py", line 64, in create_connection
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): File "C:\Python34\lib\socket.py", line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed</p>
</blockquote>