Python Forum
Reading json behind a login page
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading json behind a login page
#1
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)
Reply
#2
This file does not exist on the local PC.

No such file or directory: '../data/data.json':
Reply
#3
(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.
Reply
#4
Show us your PHP code.
Then we can convert it to Python.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeRoor reading json GreenLynx 3 846 May-16-2023, 01:47 PM
Last Post: buran
  Reading Data from JSON tpolim008 2 1,075 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  How to return the next page from json recursively? sandson 0 1,145 Apr-01-2022, 11:01 PM
Last Post: sandson
  Initializing, reading and updating a large JSON file medatib531 0 1,767 Mar-10-2022, 07:58 PM
Last Post: medatib531
  Help with reading json file hhchenfx 5 4,480 Jul-07-2021, 01:58 PM
Last Post: hhchenfx
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,258 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  reading json file DrBrownStats 1 1,816 Nov-25-2020, 09:00 AM
Last Post: Larz60+
  Reading a json file ebolisa 2 2,155 Mar-15-2020, 09:24 AM
Last Post: ebolisa
  Reading JSON - error jmair 2 2,236 May-22-2019, 07:25 PM
Last Post: jmair
  [split] Reading json from webpage rajesh1997 1 2,189 Feb-05-2019, 12:07 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020