0

I'm using Pycharm professional 2019.03 to execute Python code Streaming Twitter Filter. The running code finish unsuccessfully with message error :

Traceback (most recent call last):

File "C:/Users/HP/PycharmProjects/Twitter_Stream/twitter_filter.py", line 12, in <module>
    with open(file_path) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/config/api.json'

When I ran the script print(os.getcwd()) the result is C:\Users\HP\PycharmProjects\Twitter_Stream The Run/Debug configurations Windows show that the working directory is C:\Users\HP\PycharmProjects\Twitter_Stream and all seem ok but I dont know why this message error. The api.json file is in the same directory than twitter_filter.py

I tried to replace the code : file_path = '/config/api.json' by file_path = '/Users/HP/PycharmProjects/Twitter_Stream/config/api.json' or file_path = 'C:/Users/HP/PycharmProjects/Twitter_Stream/config/api.json', I have this message error :

Traceback (most recent call last):
  File "C:/Users/HP/PycharmProjects/Twitter_Stream/twitter_filter.py", line 13, in <module>
    twitter_api = json.loads(f.read())
  File "C:\Users\HP\Anaconda3\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\HP\Anaconda3\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\HP\Anaconda3\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 3 column 5 (char 7)

Please someone can help me to solve thise problem? Let me know if you need more information

Thank you !

Ado
  • 31
  • 5

1 Answers1

0

(I would comment but I do not have enough rep points.)

When you see the JSONDecodeError, it means the JSON file is successfully being read by the module.

However, it appears the module deems the file invalid.

From past experiences, I would check if the JSON file is valid with this link: https://jsonformatter.curiousconcept.com/

I think what could be wrong is that your JSON file is using single quotes instead of double quotes, so not properly formatted.

idontknow
  • 438
  • 5
  • 16
  • In fact I think that my Json file is not properly formatted. This is my code : – Ado Jul 19 '20 at 19:54
  • Before to send you the code, I'm going to try to correct it! – Ado Jul 19 '20 at 19:55
  • XD okay, a simple `Replace (Ctrl. H)` to replace `'` for `"` should do! – idontknow Jul 19 '20 at 19:57
  • The tools to valid Json formatting still show me problems on my file. Can you help me to fix that. This is the content of my file.{ "consumer_key":'MhQGtweOFQNqeBRhumbcq69AS' "consumer_secret":'w98yHiKqDqmdHW8mpk5CvZsy1ytO7DF24DYMvNiaUtj1hPBE0g' "access_token":'1200185154825859078-qXArXtk6Fp7E9sy8JTaRke0y091QRt' "access_token_secret":'6cN7LetEWipraaZ1QZPWYs1lVTwQZdu8kY2lS0Kd5jksH' } – Ado Jul 19 '20 at 21:09
  • Yes, and they would be correct to report such a thing. You are missing commas after every entry. For example, you would need to `{"key1": "value1", "key2": "value2"}`. You are missing the comma between `"value1"` and `"key2"`. – idontknow Jul 19 '20 at 23:46
  • The problem of json file formatting is fixed, I get the same error like before. – Ado Jul 20 '20 at 00:40
  • That's odd, did you make sure to validate your JSON again? Send it again, perhaps? – idontknow Jul 20 '20 at 03:56
  • I tried ones again there is no error ! Thank you a lot. – Ado Jul 20 '20 at 16:54
  • @Ado Mark my answer as accepted? I could use the rep. Thanks! – idontknow Jul 20 '20 at 18:14