ModuleNotFoundError: No module named 'urllib3.exceptions'; 'urllib3' is not a package
Asked Answered
O

1

6

I'm using the following code to get data from a REST API:

import requests
import json

key = "my service key"

api = "http://api.data.go.kr/openapi/pblprfr-event-info-std?serviceKey=", key, "&s_page=1&s_list=100&type=json"


r = requests.get(api)

data = json.loads(r.text)

print(data["행사명"]) 

This code produces the following error:

File "sel2.py", line 1, in <module>

import requests

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/init.py", line 46, in <module>

from .exceptions import RequestsDependencyWarning

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/exceptions.py", line 9, in <module>

from urllib3.exceptions import HTTPError as BaseHTTPError

ModuleNotFoundError: No module named 'urllib3.exceptions'; 'urllib3' is not a package

Any ideas what the problem can be?

Odawa answered 25/1, 2018 at 4:37 Comment(1)
Did you figure this out? I have the same problem.Yolanthe
M
9

Most likely something got corrupted in your requests installation or it's dependencies. The following fixed the issue, for me:

# Yeah, do them one-at-a-time, in case of errors:
pip uninstall urllib3
pip install --no-cache-dir -U urllib3
pip uninstall chardet
pip install --no-cache-dir -U chardet
Malcolm answered 8/11, 2018 at 11:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.