Python Forum

Full Version: Reading json behind a login page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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

#!/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)
This file does not exist on the local PC.

No such file or directory: '../data/data.json':
(May-26-2019, 07:30 AM)heiner55 Wrote: [ -> ]This file does not exist on the local PC.

No such file or directory: '../data/data.json':


Thanks for the knowledge .I am a new user that uses this website for the best tips and tricks for python .I am trying to find out the most I can as quickly as I can so this is very helpful.
Show us your PHP code.
Then we can convert it to Python.