Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON import #57

Open
5 of 6 tasks
Tracked by #37
rburghol opened this issue Jan 11, 2023 · 3 comments
Open
5 of 6 tasks
Tracked by #37

JSON import #57

rburghol opened this issue Jan 11, 2023 · 3 comments

Comments

@rburghol
Copy link

rburghol commented Jan 11, 2023

Objectives:

import json
import requests
from requests.auth import HTTPBasicAuth
import csv
import pandas as pd

src_json_node = '...d.dh/node/62'
el_pid = 4723109
json_url = src_json_node + "/" + str(el_pid)

# authentication using rest un and pw
jfile = open("/var/www/python/auth.private")
jj = json.load(jfile)
rest_uname = jj[0]['rest_uname']
rest_pass = jj[0]['rest_pw']
basic = HTTPBasicAuth(rest_uname, rest_pass )

# Opening JSON file
jraw =  requests.get(json_url, auth=basic)
model_json = jraw.content.decode('utf-8')

# returns JSON object as 
# a dictionary
model_data = json.loads(model_json)
mlist = list(model_data)
# now extract the model using the name
model_data= model_data[mlist[0]]
for k in model_data.keys():
    print(k)
    

@jdkleiner
Copy link
Member

@rburghol
What format is your "/var/www/python/auth.private" file in? So I can test it on my end :)

I suppose we could consider storing the auth info in a single location like "/var/www/auth/auth.private" since the same login info can be used for REST calls from both R and python (we'd probably need to store the file in a format (JSON?) that makes it easy to read the rest_uname and rest_pw to variables in both R and python environments)

@rburghol
Copy link
Author

@jdkleiner Just wanted to get this in writing -- the auth.private file used here is JSON, so, that makes it an ideal candidate moving forward for a cross-platform single file.

@jdkleiner
Copy link
Member

Excellent. FWIW I ran some tests using an auth.private file in the following format:

{
    "auths": {
        "rest_uname": "un_XXXX",
        "rest_pw": "pwd_XXXX"
    },
    "src_json_node": "XXXX/d.dh/node/62"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants