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?

Helen
  • 87,344
  • 17
  • 243
  • 314
Dr.Dragon
  • 61
  • 1
  • 4

1 Answers1

8

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
not2qubit
  • 14,531
  • 8
  • 95
  • 135