叶小白
叶小白

Reputation: 69

ImportError: cannot import name 'HTMLSession' from 'requests_html'

When I tried to use the new module requests_html using the example of its website,I found the console displays information in the title.

The messages of console:

Traceback (most recent call last):
  File "C:/Users/owlish/PycharmProjects/python34/requests.py", line 2, in <module>
    from requests_html import HTMLSession
  File "C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py", line 10, in <module>
    import requests
  File "C:\Users\owlish\PycharmProjects\python34\requests.py", line 2, in <module>
    from requests_html import HTMLSession
ImportError: cannot import name 'HTMLSession' from 'requests_html' (C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py)

code:

from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://python.org/')

I expect it to work without an error,like the examples https://html.python-requests.org/.

Upvotes: 1

Views: 12799

Answers (1)

叶小白
叶小白

Reputation: 69

With AhmedHawary's help,I found the reason for the error:I had a file named requests.py , which confilcted with the keywords . It worked fine after I renamed the file name.

Upvotes: 5

Related Questions