-2

When I try to execute simple programs using the requests module in python 3, It gives me the following error which seems to be linked to the module in itself.

Traceback (most recent call last):
  File "req.py", line 1, in <module>
    import requests 
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/urllib3/__init__.py", line 11, in <module>
    from . import exceptions
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/urllib3/exceptions.py", line 3, in <module>
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 914, in _find_spec
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/urllib3/packages/six.py", line 192, in find_spec
    return spec_from_loader(fullname, self)
  File "<frozen importlib._bootstrap>", line 422, in spec_from_loader
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/urllib3/packages/six.py", line 222, in is_package
    return hasattr(self.__get_module(fullname), "__path__")
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/urllib3/packages/six.py", line 121, in __getattr__
    _module = self._resolve()
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/urllib3/packages/six.py", line 118, in _resolve
    return _import_module(self.mod)
  File "/Users/redacted/Library/Python/3.8/lib/python/site-packages/urllib3/packages/six.py", line 87, in _import_module
    __import__(name)
  File "/Users/redacted/Desktop/python/http1/http.py", line 1
    HTTP -- hypertext transfer protocol 
                      ^
SyntaxError: invalid syntax

The program was the simplest get request. I don't know what's going on.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • What is the version of your setuptools ? – Keshav Biyani Oct 30 '21 at 17:53
  • 1
    Don't name your file http.py - its being imported instead of the stdlib module. – SuperStormer Oct 30 '21 at 17:53
  • Welcome to Stack Overflow! Please take the [tour] and read [ask]. In the future, please write a more descriptive title, like depending on how much of the traceback you understand, "Why is requests not able to import urllib3?" or "Why is six trying to import my own http module?" – wjandrea Oct 30 '21 at 18:01

1 Answers1

1

It looks like the error is coming from the line:

HTTP -- hypertext transfer protocol

Python is trying to parse this as code so you should make this a comment:

# HTTP -- hypertext transfer protocol

Or as a string:

"HTTP -- hypertext transfer protocol"

Also, I would avoid naming your file http.py as this is the name of a Python standard library module.

Rob Kwasowski
  • 2,690
  • 3
  • 13
  • 32
  • 3
    This is only part of the problem. The main problem is that OP named their module `http`, which is shadowing the [standard library module](https://docs.python.org/3/library/http.html). – wjandrea Oct 30 '21 at 17:58