Python Forum
Thread Rating:
  • 3 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
installing json
#1
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.
Reply
#2
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.
Recommended Tutorials:
Reply
#3
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 it
For working with API is Requests very good,
it can do the job of build in of json and urllib in an easier way.
Reply
#4
Well, here's my code, I just get an:

Error:
{'error': 'not found'}
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.
Reply
#5
That website doesnt show a hash table at all, but a list.
Recommended Tutorials:
Reply
#6
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)
                                       
Output:
{'description': 'A few more centaur herds are thinned out.',   'flags': ['Permanent'],                                       'id': 1,                                                      'locked_text': '',                                            'name': 'Centaur Slayer',                                     'requirement': 'Kill  centaurs.',                             'tiers': [{'count': 10, 'points': 1},                                   {'count': 100, 'points': 5},                                  {'count': 500, 'points': 5},                                  {'count': 1000, 'points': 5}],                      'type': 'Default'}                                           >>> json_data['description'] 'A few more centaur herds are thinned out.'
Reply
#7
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!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020