installing json - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: installing json (/thread-4666.html) |
installing json - Only_On_Tuesdays - Sep-01-2017 Hi, first of all I'm new here so hello everyone! I have an issue. I'm trying to learn how to work with a specific API and I need JSON to do it. I used pip to install simplejson, but this didn't allow my code to work. So I then used pip to install json, or tried, but I keep getting a failure in command prompt (I'm on Windows). C:\Users\spect>pip install json Collecting json Using cached json-99.0.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\spect\AppData\Local\Temp\pip-build-tfkprp8j\json\setup.py", line 2, in <module> raise RuntimeError("Package 'json' must not be downloaded from pypi") RuntimeError: Package 'json' must not be downloaded from pypi ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in C:\Users\spect\AppData\Local\Temp\pip-build-tfkprp8j\json\It's obvious to me what the issue is, pypi, but I don't really know how to install anything in python except using pip. RE: installing json - metulburr - Sep-01-2017 json is apart of the standard library https://docs.python.org/3/library/json.html You are going to need to be more specific on how your code did not work. RE: installing json - snippsat - Sep-01-2017 json is a built-in module, you don't need to install it with pip. Quote:I'm trying to learn how to work with a specific API and I need JSON to do itFor working with API is Requests very good, it can do the job of build in of json and urllib in an easier way. RE: installing json - Only_On_Tuesdays - Sep-01-2017 Well, here's my code, I just get an: as a reponse.import urllib.parse import requests main_api = 'https://api.guildwars2.com/v2/achievements' address = 'achievements' url = main_api + urllib.parse.urlencode({'address': address}) json_data = requests.get(url).json() print(json_data) I just figured out it wasn't the code that wasn't working, it was a typo in the way the API processes requests. Well, step one down. Many more to go. Sorry about the flacid question guys. RE: installing json - metulburr - Sep-02-2017 That website doesnt show a hash table at all, but a list. RE: installing json - snippsat - Sep-02-2017 You are making wrong API call,also missing achievements / But if fix that still not work. >>> import urllib.parse ... import requests ... ... main_api = 'https://api.guildwars2.com/v2/achievements/' ... url = main_api + urllib.parse.urlencode({'address': address}) ... json_data = requests.get(url).json() ... print(json_data) {'text': 'no such id'}Doc for API Just to make a link that work. >>> import urllib.parse ... import requests ... from pprint import pprint ... ... main_api = 'https://api.guildwars2.com/v2/achievements/' ... url = main_api + urllib.parse.urlencode({'1?lang': 'en'}) ... json_data = requests.get(url).json() ... pprint(json_data)
RE: installing json - Only_On_Tuesdays - Sep-02-2017 Thanks snippsat. I'm going to read the urllib documentation so I don't do this mistake again. Got it working, so I appreciate all you guys' help! |