Loading a file throwing 401 REST API Error

I am trying to load a simple file through a loading Job to TigerGraph cloud and getting an error like below.

conn = tg.TigerGraphConnection(host=hostName, graphname="MyGraphCopy", username=userName, password=password, apiToken=token)

result = conn.gsql("""
USE GRAPH MyGraphCopy 

BEGIN
CREATE LOADING JOB load_persons FOR GRAPH MyGraphCopy {
      DEFINE FILENAME MyDataSource;
      LOAD MyDataSource TO VERTEX Person VALUES($5, $1, $2, $3, $4) USING SEPARATOR=",", HEADER="true", EOL="\n", QUOTE="double";
    }
END
""")

print(result)

Using graph 'MyGraphCopy'
Successfully created loading jobs: [load_persons].

results = conn.gsql("""
USE GRAPH MyGraphCopy 
SHOW JOB load_persons
""")

print(results)

Using graph 'MyGraphCopy'
- CREATE LOADING JOB load_persons FOR GRAPH MyGraphCopy {
DEFINE FILENAME MyDataSource;
LOAD MyDataSource TO VERTEX Person VALUES($5, $1, $2, $3, $4) USING SEPARATOR=",", 
HEADER="true", EOL="
", QUOTE="double";
}

persons_file = './data/MyGraph_Person.csv'
line_no = 0
with open(persons_file, 'r') as f:
    for line in f:
        line_no += 1
        print(line[:-1])
        if line_no >= 5:
            break

id,name,email,username,created_at,v_id
1,Marvin Geistmann,mgeistmann0@accuweather.com,mgeistmann0,2018-09-30 07:31:34,1
10,Mead Amberger,mamberger9@sun.com,mamberger9,2019-11-18 23:58:17,10
100,Wendeline Sherar,wsherar2r@kickstarter.com,wsherar2r,2018-09-30 17:27:25,100
11,Vaughan Gerrans,vgerransa@shutterfly.com,vgerransa,2019-04-24 19:33:22,11

results = conn.uploadFile(persons_file, fileTag='MyDataSource', jobName='load_persons')
print(json.dumps(results, indent=2))

HTTPError: 401 Client Error: Unauthorized for url: 

https://<my_domain>.i.tgcloud.io:9000/ddl/MyGraphCopy?tag=load_persons&filename=MyDataSource

Not sure what I am not doing right here. Any help is much appreciated.

Figured this one out. I had to use a new secret that is created for the new graph.

The token I was using that was created for the other graph named MyGraph would let me do pretty much everything in graph MyGraphCopy except running a load job.

1 Like

Was just thinking along the same lines! Glad you figured out – hopefully this helps the next person that runs into HTTPError: 401 Client Error: Unauthorized for url: error.