Home > Back-end >  Python 3 - Pycharm - Jira REST API - Error: module 'http' has no attribute 'client�
Python 3 - Pycharm - Jira REST API - Error: module 'http' has no attribute 'client�

Time:12-22

hope you're all fine

You'll see, I'm using PyCharm 2022.3 (Community Edition) with Python 3.9.7, and I'm trying to execute the following code:

#!/usr/bin/env python3

# Required libraries for the program.
import requests as req
from requests.auth import HTTPBasicAuth
import json

url = "https://your-domain.atlassian.net/rest/api/2/user"

auth = HTTPBasicAuth("[email protected]", "xXx_token_xXx")

headers = {
  "Accept": "application/json"
}

query = {
  'accountId': '934250915yfe67e125d6062v'
}

response = req.request(
   "GET",
   url,
   headers=headers,
   params=query,
   auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

It comes from: Jira REST API - Get user

And I'm getting the following error:

Traceback (most recent call last):
  File "C:\Users\username\Desktop\GitHubProjects\Tests\email.py", line 4, in <module>
    import requests as req
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\__init__.py", line 43, in <module>
    import urllib3
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\__init__.py", line 11, in <module>
    from . import exceptions
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\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 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 565, in module_from_spec
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 234, in create_module
    return self.load_module(spec.name)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 209, in load_module
    mod = mod._resolve()
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 118, in _resolve
    return _import_module(self.mod)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 87, in _import_module
    __import__(name)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 71, in <module>
    import email.parser
  File "C:\Users\username\Desktop\GitHubProjects\Tests\email.py", line 5, in <module>
    from requests.auth import HTTPBasicAuth
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\auth.py", line 16, in <module>
    from ._internal_utils import to_native_string
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\_internal_utils.py", line 10, in <module>
    from .compat import builtin_str
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\compat.py", line 47, in <module>
    from http import cookiejar as cookielib
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\cookiejar.py", line 36, in <module>
    import urllib.parse, urllib.request
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1379, in <module>
    if hasattr(http.client, 'HTTPSConnection'):
AttributeError: module 'http' has no attribute 'client'

The weird thing is... it only happens when I run the code like this: Running code with Pycharm default runner

But, it works when I select "Run File in Python Console" (as you can see the choice in the image above)

So... I don't know what is going on

I have tried some things:

  • pip install http
  • pip install -U http
  • pip install -U setuptools

And a lot of other bunch of commands

I'm a bit lost on what to do... Could you give me a hand?

Thanks in advance

CodePudding user response:

The name of your file that you created is email.py. The name of a module required for the JIRA Python library to work is also called email. This causes a conflict which creates the error.

This is noticeable in your traceback:

 import email.parser
  File "C:\Users\username\Desktop\GitHubProjects\Tests\email.py", line 5, in <module>

You can fix this by renaming your file to something else.

  • Related