0

I am Following Chris P's 'Visualize Real-world JSON Data in Blender (3D Chart Animation Nodes Tutorial)' on YouTube but I seem to have got stuck at the first hurdle of importing the data. I have followed his instructions completely and am unsure why the script keeps failing. I have attached his script, My script, my file location, my error message and a snap shot of his video. I am On windows OS, he is on Linux I'menter image description here not sure if that makes a difference. Here is the link to the video: https://www.youtube.com/watch?v=0aRjInmibSw&t=1055s THE TIMESTAMP FOR HIS CODE IS 6 min.

FILE NAME: Export.json

MY FILE LOCATION: C:\Users\Jordan\Downloads

MY CODE

import json

with open(r'C:/Users/Jordan/Downloads/Export.json','r') as f: 
      j=json.load(f) 
      print (j) 

MY ERROR MESSAGE:

Traceback (most recent call last):
  File "D:\Mixed Graphs\Blender json\3D Charts.blend\My Script", line 3, in <module>
OSError: [Errno 22] Invalid argument: '/C:/Users/Jordan/Downloads/Export'
Error: Python script failed, check the message in the system console

HIS CODE:

import json

with open('/Home/chris/downloads/tutorial1.json') as f: 
    json.load(f) 
    print (j) 
  • Typo. `'/C:/Users/...'` should just be `'C:/Users/...'`. – Random Davis Nov 05 '20 at 17:31
  • I have just changed it but it still seems to be displaying the same error message unfortunately. Thank you for the super fast reply though!!!! – Stacy Jordans Nov 05 '20 at 17:34
  • Well, `print (j)` is going to fail because you never defined `j`. Did you mean to put `j = json.load(f)`? As for the invalid argument error, do you still get it if you use backslashes instead? You'll have to prepend `r` to the string like `r'C:\Users\...'`. Also add `'r'` to your `open`, like `with open('path', 'r') as f:` – Random Davis Nov 05 '20 at 17:40
  • `import json with open(r'C:\Users\Jordan\Downloads\Export.json','r') as f: j=json.load(f) print (j)` I've tried both ways and it still cant seem to find the file. Thanks for commenting though :) Also I cant seem to format these comments very well I apologise for that. – Stacy Jordans Nov 05 '20 at 17:50
  • I'd recommend updating the question itself with your updated code, actually. Also are you still getting the same error or is it a different one? – Random Davis Nov 05 '20 at 18:02
  • Thank you for the advice I have just updated it. Yes it is still the same error code. – Stacy Jordans Nov 05 '20 at 18:08
  • Is the path appearing any differently in the error? Are you saving beforehand? Just want to make sure you're actually running the code you think you are. Is the `Export.json` part of your path shown in the error? I notice it was left out in the error you posted. – Random Davis Nov 05 '20 at 18:12

1 Answers1

0

Your problem seems to be that you're using "/"(slash) instead of ""(backslash) on Windows. In addition you need to use two "\" as one backslash signals an escaping for the next character.

Fix therefore should be:

import json

with open(r'C:\\Users\\Jordan\\Downloads\\Export.json','r') as f: 
      j=json.load(f) 
      print (j)
Bouncing Bit
  • 358
  • 2
  • 14