python 的 EOFError: EOF when reading a line 是什么原因?
怪我咯
怪我咯 2017-04-17 11:25:43
0
2
2685

在程序执行过程中,出现过如题的错误信息。

google了一些,好像是python或部署的原因,但是有这些错误信息:


   Traceback (most recent call last):

   ...

   File "/usr/local/lib/python2.7/urllib.py", line 84, in urlopen
    return opener.open(url)

  File "/usr/local/lib/python2.7/urllib.py", line 205, in open
    return getattr(self, name)(url)

  File "/usr/local/lib/python2.7/urllib.py", line 356, in open_http
    return self.http_error(url, fp, errcode, errmsg, headers)

  File "/usr/local/lib/python2.7/urllib.py", line 369, in http_error
    result = method(url, fp, errcode, errmsg, headers)

  File "/usr/local/lib/python2.7/urllib.py", line 663, in http_error_301
    return self.http_error_302(url, fp, errcode, errmsg, headers, data)

  File "/usr/local/lib/python2.7/urllib.py", line 632, in http_error_302
    data)

  File "/usr/local/lib/python2.7/urllib.py", line 659, in redirect_internal
    return self.open(newurl)

  File "/usr/local/lib/python2.7/urllib.py", line 205, in open
    return getattr(self, name)(url)

  File "/usr/local/lib/python2.7/urllib.py", line 356, in open_http
    return self.http_error(url, fp, errcode, errmsg, headers)

  File "/usr/local/lib/python2.7/urllib.py", line 369, in http_error
    result = method(url, fp, errcode, errmsg, headers)

  File "/usr/local/lib/python2.7/urllib.py", line 694, in http_error_401
    return getattr(self,name)(url, realm)

  File "/usr/local/lib/python2.7/urllib.py", line 758, in retry_http_basic_auth
    user, passwd = self.get_user_passwd(host, realm, i)

  File "/usr/local/lib/python2.7/urllib.py", line 787, in get_user_passwd
    user, passwd = self.prompt_user_passwd(host, realm)

  File "/usr/local/lib/python2.7/urllib.py", line 796, in prompt_user_passwd
    host))

EOFError: EOF when reading a line

这是权限问题?

到底是什么问题呢?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
巴扎黑

According to the poster’s reply in the comments, if you want to continue using urllib, you can use FancyURLopener and define a prompt_user_password method yourself.

The ease of use of urllib is indeed often criticized. So another way is to switch to a more usable library. I recommend python-requests. Using this library you can write like this (copied from that link):

>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
u'{"type":"User"...'
伊谢尔伦

When installing SublimeREPL and then compiling a python file, you can select [Tools] - [sublimeREPL] - [python] - [Python - RUN current file] to prompt the user for input. It should be able to solve the problem of error reporting when using the raw_input function under sublime.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template