Skip to content

Commit

Permalink
Merge pull request #251 from tigergraph/GML-1888-pytg-gettoken-error-…
Browse files Browse the repository at this point in the history
…message-port-config

fix port config for v4, add token error messaging
  • Loading branch information
parkererickson-tg authored Sep 23, 2024
2 parents 44c0d8f + 17dff31 commit 1095a8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pyTigerGraph/pyTigerGraphAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def getToken(self, secret: str = None, setToken: bool = True, lifetime: int = No
if e.response.status_code == 404:
res = self._post(self.restppUrl+"/requesttoken", authMode="pwd", data=str({"graph": self.graphname}), resKey="results")
mainVer = 3
if e.response.status_code == 400:
raise TigerGraphException("Error requesting token. Check if the connection's graphname is correct.", 400)
else:
raise e
success = True
Expand Down
12 changes: 6 additions & 6 deletions pyTigerGraph/pyTigerGraphBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def __init__(self, host: str = "http://127.0.0.1", graphname: str = "MyGraph",
else:
self.restppPort = restppPort
self.restppUrl = self.host + ":" + self.restppPort
self.gsPort = ""
gsPort = str(gsPort)
self.gsPort = gsPort
if self.tgCloud and (gsPort == "14240" or gsPort == "443"):
self.gsPort = sslPort
self.gsUrl = self.host + ":" + sslPort
Expand Down Expand Up @@ -344,11 +344,11 @@ def _req(self, method: str, url: str, authMode: str = "token", headers: dict = N
# In TG 4.x the port for restpp has changed from 9000 to 14240.
# This block should only be called once. When using 4.x, using port 9000 should fail so self.restppurl will change to host:14240/restpp
# ----
# Changes port to 14240, adds /restpp to end to url, tries again, saves changes if successful
if self.restppPort == "9000" and "9000" in url:
newRestppUrl = self.host + ":14240/restpp"
# Changes port to gsql port, adds /restpp to end to url, tries again, saves changes if successful
if "/restpp" not in url or self.tgCloud:
newRestppUrl = self.host + ":"+self.gsPort+"/restpp"
# In tgcloud /restpp can already be in the restpp url. We want to extract everything after the port or /restpp
if '/restpp' in url:
if self.tgCloud:
url = newRestppUrl + '/' + '/'.join(url.split(':')[2].split('/')[2:])
else:
url = newRestppUrl + '/' + '/'.join(url.split(':')[2].split('/')[1:])
Expand All @@ -358,7 +358,7 @@ def _req(self, method: str, url: str, authMode: str = "token", headers: dict = N
res = requests.request(method, url, headers=_headers, data=_data, params=params, verify=verify)
res.raise_for_status()
self.restppUrl = newRestppUrl
self.restppPort = "14240"
self.restppPort = self.gsPort
else:
raise e

Expand Down

0 comments on commit 1095a8f

Please sign in to comment.