【问题标题】:urllib doesn't work properlyurllib 无法正常工作
【发布时间】:2017-09-01 16:38:19
【问题描述】:

我正在尝试将 urllib 用于以下简单请求:

      import urllib
      my_url = "https://realpython.com/practice/aphrodite.html"
      my_open = urllib.request.urlopen(my_url)
      my_op = my_open.read().decode('utf-8')
      print(my_op)

当我运行代码时,它会从我的数据库返回与 urllib 无关的请求。此外,我收到如下错误:

  import urllib.request
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 88, in <module>
    import http.client
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 71, in <module>
    import email.parser
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/feedparser.py", line 27, in <module>
    from email import message
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/message.py", line 16, in <module>
    from email import utils
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/utils.py", line 29, in <module>
    import socket
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 52, in <module>
    import os, sys, io, selectors
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/selectors.py", line 290, in <module>
    class SelectSelector(_BaseSelectorImpl):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/selectors.py", line 317, in SelectSelector
    _select = select.select
AttributeError: module 'select' has no attribute 'select'

我可以卸载和安装除 urllib 之外的任何库。请指导我解决此错误。

【问题讨论】:

  • 可能您有一个名为select.py 的文件位于某个隐藏内置select 模块的地方。 import select; print(select.__file__) 会告诉你它在哪里。
  • 我也检查过。我没有像 select.py 这样的文件
  • 请粘贴完整回溯。我们这里所拥有的并不是完整的回溯。
  • 你是如何安装 Python 3 的? (您有什么理由使用系统 Python 3,而不是 brew 安装的系统吗?)
  • 解决了。创建了没有任何代码的免费 select.py 现在它可以工作了,非常感谢大家。

标签: python python-3.x python-requests urllib


【解决方案1】:

我创建了一个名为 select.py 的单独文件,并且没有包含任何代码。之后,我没有收到任何错误。

【讨论】:

    猜你喜欢
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 2012-07-11
    • 2018-04-08
    • 2017-04-20
    • 2018-10-02
    • 2016-09-04
    相关资源
    最近更新 更多