0

I get this error when running the script ? Anyone knows what the main problem is ? already import the json and installed simplejson and it still sits.

{'error': {'code': 400, 'message': 'Bad Request'}}
72
Traceback (most recent call last):
  File "test.py", line 212, in <module>
    main()
  File "test.py", line 203, in main
    found = ticket_swap_bot.gather_data_for_event(event)
  File "test.py", line 178, in gather_data_for_event
    if r.json().get('success', False):
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Incognito
  • 1
  • 2

1 Answers1

0

When you use json.loads() you should pass a string to it. according to your question you are passing a dictionary to it, and this is important to use " for json keys and values, take a look at his example, this might help you:

 > j = '{"error": {"code": 400, "message": "Bad Request"}}'
 > json.loads(j)
 {'error': {'code': 400, 'message': 'Bad Request'}}

and this is a bad ways to do it:

> a = "{'error': {'code': 400, 'message': 'Bad Request'}}" # a is string but not json format
> json.loads(a)

JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

and one more wrong way:

> a = {'error': {'code': 400, 'message': 'Bad Request'} # a is a dict
> json.loads(a)

TypeError: the JSON object must be str, not 'dict'
Mehrdad Pedramfar
  • 10,941
  • 4
  • 38
  • 59