Network path format

Hi hope all is well, could someone help please with a topic i’m trying to achieve with no avail and after looking at various solutions i seem to get the same problem creating a file using a server address, tried the forward slash answers backslash (tried doubling up the backslashes), tried putting the path in a variable , tried pathlib, not sure i was using that correctly.
Initially i tried with success saving to hard drive with :

##        # Writing to json
##    with open("C:\GUIpython\pwa1.json", "w") as outfile:
##        outfile.write(json_object)

##        # Writing to sample.json
##    with open("PWAline1.json", "w") as outfile:
##        outfile.write(json_object)

it was when i was trying to add the server i get issues,here’s what im trying to do

    # Writing to json
    with open("\\XX.XXX.XX.XX\ICT\PWALine1.json", "w") as outfile:

could someone give a working example please to try , that would be considered good practice, any help would be greatly appreciated


The \ is the python string escape character.
If you want one \ you must type two \.
Or you can make your strings raw strings like this r”\\host\path”

Hi Barry thank for the reply, i’m still getting the error this time I’ve included the exact code i’m using and the error being generated

My Code :

 # Writing to json
    with open(r"\\\ICT\PWALine1.json", "w") as outfile:

and the error generated.

 File "C:\GUIpython\", line 77, in check
    with open(r"\\\ICT\PWALine1.json", "w") as outfile:
FileNotFoundError: [Errno 2] No such file or directory: '\\\\\\ICT\\PWALine1.json'

if this makes it any clearer what i’m doing wrong, i tried doubling up also and still an error.


Is a place holder for an ip address?

Teat the path in a cmd terminal window.
Does this work?

dir \\\ICT

Hi , comes back with the network name cannot be found

it is a place holder , yes

It will not work until you put a real path in your code right?

hi, i put the actual ip address when i tried it. the xx was just the format i was using,i can reach the folder ok in windows its a mapped drive

Can you create files in that folder from CMD?
Maybe its a readonly folder?

In CMD does this work?

echo Testing 1 2 3 >\\\ICT\PWALine1.json

The no such file error suggests that its the folder that is wrong of the server address.

I tried that and got the network name cannot be found, which is strange as that’s the address i use in labview to send the files from an automated tester. I’m new to python and was trying to get the files to send through a program to manually send files as a learning project, after i got it working to the c drive thought it was just a matter of adding the server address and that would be it…

Ok that shows that its a windows/network issue not a python problem.
You will need to figure what the correct way to access the server file system is.

Do you have an account on the server and is it the same username and password as on your windows system you are testing from?
If not you are likely to get permission errors.

ok thanks for your help, i use the path everyday for Labview programming and for connecting raspberry pi to webpages on that server,the path just doesn’t seem to translate to python for some reason…oh well thanks again

You have proved that is does not work from CMD right?
The echo test fails for you without python being involved.

i’ve got some code that seems to work pinging network address , i’ll try it again when i’m back in the office tomorrow in case there’s an issue with the vpn, but tried most things when i was there last week