'python requests library errors that i cannot resolve

I have been looking for any answer to this for the past 12-hours and I'm finding nothing.

import requests

class TypeSpeed:
    def __init__(self):
        url = "https://www.mit.edu/~ecprice/wordlist.10000"
        r = requests.get(url)
        s = r.content.splitlines()
        
        print(s)
        input("type here:   ")
        # wpm calc

TypeSpeed()

This is my code. At first, I was consistently getting the error:

ImportError: cannot import name 'Union' from 'typing'

With the traceback:

  File "/home/sam/workspace/personal/proj/type-speed/typing.py", line 2, in <module>
    import requests
  File "/usr/lib/python3.10/site-packages/requests/__init__.py", line 134, in <module>
    from . import packages
  File "/usr/lib/python3.10/site-packages/requests/packages.py", line 15, in <module>
    locals()[package] = __import__(package)
  File "/usr/lib/python3.10/site-packages/idna/__init__.py", line 2, in <module>
    from .core import (
  File "/usr/lib/python3.10/site-packages/idna/core.py", line 5, in <module>
    from typing import Union, Optional

Changed some stuff around but ultimately changed it all back to the way it was. Now, I am getting a different error that I don't understand!

  AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)

  File "/home/sam/workspace/personal/proj/type-speed/typing.py", line 1, in <module>
    import requests
  File "/usr/lib/python3.10/site-packages/requests/__init__.py", line 134, in <module>
    from . import packages
  File "/usr/lib/python3.10/site-packages/requests/packages.py", line 15, in <module>
    locals()[package] = __import__(package)
  File "/usr/lib/python3.10/site-packages/idna/__init__.py", line 2, in <module>
    from .core import (
  File "/usr/lib/python3.10/site-packages/idna/core.py", line 5, in <module>
    from typing import Union, Optional
  File "/home/sam/workspace/personal/proj/type-speed/typing.py", line 13, in <module>
    TypeSpeed()
  File "/home/sam/workspace/personal/proj/type-speed/typing.py", line 6, in __init__
    r = requests.get(url)

Any assistance in where I'm going wrong would be appreciated, I have literally written this exact code like 30 times in the past and I have no clue why it would throw this error. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source