Feb-25-2019, 12:47 PM
Hi,
I'm trying to read json data from a file which is located in a protectd directory.
I can get to the data without a problem using php code so, I know the data is accessible.
With the following code, I go through the credentials but I get an [Errno 2] No such file or directory: '../data/data.json'.
How do I list the content of the directory so I can troubleshoot my problem?
Any help is appreciated.
TIA
I'm trying to read json data from a file which is located in a protectd directory.
I can get to the data without a problem using php code so, I know the data is accessible.
With the following code, I go through the credentials but I get an [Errno 2] No such file or directory: '../data/data.json'.
How do I list the content of the directory so I can troubleshoot my problem?
Any help is appreciated.
TIA
#!/usr/bin/python3
#http://kazuar.github.io/scraping-tutorial/
from __future__ import print_function
import requests as req
import json
#url
login_url = "http://mysite:500"
#data file
fname = "../data/data.json" #full path /home/pi/Washup/data/data.json
#htaccess set up
user = "me"
password = "mypass"
try:
r = req.get(login_url, auth=(user, password))
#print(r.text) #prints index.php content
if(r.status_code == req.codes.ok):
#good, we are in
with open(fname, "r+") as jsonFile:
data = json.load(jsonFile)
print(data)
except IOError as e:
print(e)
