Requesttoken returning error: REST-1101 - Expected JSON but got query string

Hi.

When I’m calling /requesttoken (either via Python or Postman) I’m getting the following error message:

{"code":"REST-1101","error":true,"message":"The request cannot be processed: expected a JSON payload, but a query string was given.\nPlease visit https://docs.tigergraph.com/tigergraph-server/current/api/built-in-endpoints#_authentication for more information.","token":""}

My Python code looks like this:

conn = tg.TigerGraphConnection(
    host=server,
    graphname='blah',
    username='tigergraph',
    password='bigsecret',
    useCert=True
    )
print('Connected')

secret = conn.createSecret()
print(secret)

token = conn.getToken(secret)

I’m getting secrets - I can see them being created in Graph Studio. I only have a single solution/database.

Regards,
Gordon

@gordonc you mentioned secrets are being created.

When you run this do you see the secret being printed:

secret = conn.createSecret()
print(secret)

Yes - I get the secret printed and I can see it being created in Graph Studio.

Hi @gordonc

Thanks for reporting this issue, actually we just made a release for the pyTigerGraph ( 0.0.9.8.8 ) to support the product change in 3.4+ ( requesttoken is POST )
Feel free to upgrade pyTigerGraph using

pip install -U pyTigerGraph

And for the PostMan calls please find below docs to explore the changes :

1 Like

Hi @Mohamed_Zrouga ,
I am also facing the same issue. I tried updating pyTigerGraph as mentioned above but no luck. Any suggestions/roundabouts to make this work.

Here are my connect parameters for pyTigerGraph, this is working with all versions

host = "http://myhost"
graphname = "myGraph"
username = "tigergraph"
password = "tigergraph"
gsqlversion = "3.4.0"
usecert = True
secret = "somethingveryrandom"
tokenlifetime = 26000000
restppPort = 9000
gsPort = 443

And the connect itself:

import cfg
tgconn = tg.TigerGraphConnection(host=cfg.host, graphname=cfg.graphname, username=cfg.username,
                                 password=cfg.password, restppPort=cfg.restppPort, gsPort=cfg.gsPort, useCert=False, gsqlVersion=cfg.gsqlversion)
cfg.token = tgconn.getToken(cfg.secret, cfg.tokenlifetime)

For a reference, my pyTigerGraph version. Maybe you need to install package using pip3 ?

pip3 show pyTigerGraph 
Name: pyTigerGraph
Version: 0.0.9.8.8
Summary: Library to connect to TigerGraph databases
Home-page: https://github.com/pyTigerGraph/pyTigerGraph
Author: Zrouga Mohamed / Jonathan Herke / Parker Erickson / Szilard Barany / TigerGraph
Author-email: medzrouga@gmail.com
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires: pandas, pyTigerDriver, requests, validators
Required-by:
1 Like

@Bruno_Simic Thanks a lot for the explanation!
as @Bruno_Simic mentioned: @mt_nagarro @gordonc you should use at least pyTigerGraph version 0.9.8.8, to support both token requests GET/POST ( TigerGraph 3.4+ )

Let me know if you have any other issues :slight_smile: !

I am also getting the same error, using pyTigerGraph v 0.9.9.0.

It looks like we can only authenticate using secrets created directly in the TG cloud portal.

When trying to do the following flow:

import json
import pyTigerGraph as tg

CONFIG = json.load(open('config.json'))

conn = tg.TigerGraphConnection(
    host=CONFIG['host'],
    graphname=CONFIG['graph_name'],
    username=CONFIG['username'],
    password=CONFIG['password']
)

conn.getToken(CONFIG['api_secret'], setToken=True, lifetime=10000)

I can get an authToken.

However, if I try to do the following (using the createSecret method):

conn.getToken(conn.createSecret(), setToken=True, lifetime=10000)

I get the same error as others in this thread, even though I can see the secrets are getting created in the portal.

It also looks like I cannot get a token if I have already executed a GSQL command using the connection.

E.g.

This works:

conn = tg.TigerGraphConnection(
    host=CONFIG['host'],
    username=CONFIG['username'],
    password=CONFIG['password']
)

conn.graphname = 'test'
authToken = conn.getToken(CONFIG['test_api_secret'], setToken=True, lifetime=10000)

But this does not (the only difference is a single extra line):

conn = tg.TigerGraphConnection(
    host=CONFIG['host'],
    username=CONFIG['username'],
    password=CONFIG['password']
)

print(conn.gsql('ls', options=[]))

conn.graphname = 'test'
authToken = conn.getToken(CONFIG['test_api_secret'], setToken=True, lifetime=10000)

What happen if you omit setToken=true in getToken ?

Tried again without the setToken argument, but still encounter the same error.

code:

import json
import pyTigerGraph as tg

CONFIG = json.load(open('config.json'))

conn = tg.TigerGraphConnection(
    host=CONFIG['host'],
    graphname=CONFIG['graph_name'],
    username=CONFIG['username'],
    password=CONFIG['password']
)

# authToken = conn.getToken(CONFIG['api_secret'])  # this way works
authToken = conn.getToken(conn.createSecret())  # this way does not work

Error message:

---------------------------------------------------------------------------
TigerGraphException                       Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_24412/1780925938.py in <module>
     10 CONFIG['test_api_secret'] = conn.createSecret()
     11 
---> 12 authToken = conn.getToken(CONFIG['test_api_secret'])

~\miniconda3\envs\tg\lib\site-packages\pyTigerGraph\pyTigerGraph.py in getToken(self, secret, setToken, lifetime)
   1413         if "Endpoint is not found from url = /requesttoken" in res["message"]:
   1414             raise TigerGraphException("REST++ authentication is not enabled, can't generate token.", None)
-> 1415         raise TigerGraphException(res["message"], (res["code"] if "code" in res else None))
   1416 
   1417     def refreshToken(self, secret, token=None, lifetime=2592000):

TigerGraphException: ('The request cannot be processed: expected a JSON payload, but a query string was given.\nPlease visit https://docs.tigergraph.com/tigergraph-server/current/api/built-in-endpoints#_authentication for more information.', 'REST-1101')