From 7b2eee767b4a0399e2c2d0aaed285f911db4f721 Mon Sep 17 00:00:00 2001 From: Chengbiao Jin Date: Tue, 5 Nov 2024 00:00:53 +0000 Subject: [PATCH] add support for non-ascii character in string --- pyTigerGraph/pyTigerGraphLoading.py | 9 +++++++-- pyTigerGraph/pytgasync/pyTigerGraphLoading.py | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pyTigerGraph/pyTigerGraphLoading.py b/pyTigerGraph/pyTigerGraphLoading.py index 49a28736..0d3cede8 100644 --- a/pyTigerGraph/pyTigerGraphLoading.py +++ b/pyTigerGraph/pyTigerGraphLoading.py @@ -161,8 +161,13 @@ def runLoadingJobWithData(self, data: str, fileTag: str, jobName: str, sep: str if eol is not None: params["eol"] = eol - res = self._req("POST", self.restppUrl + "/ddl/" + self.graphname, params=params, data=data, - headers={"RESPONSE-LIMIT": str(sizeLimit), "GSQL-TIMEOUT": str(timeout)}) + if isinstance(data, str): + data = data.encode("utf-8") + res = self._req("POST", self.restppUrl + "/ddl/" + self.graphname, params=params, data=data, + headers={"Content-Type": "application/x-www-form-urlencoded; Charset=utf-8", "RESPONSE-LIMIT": str(sizeLimit), "GSQL-TIMEOUT": str(timeout)}) + else: + res = self._req("POST", self.restppUrl + "/ddl/" + self.graphname, params=params, data=data, + headers={"RESPONSE-LIMIT": str(sizeLimit), "GSQL-TIMEOUT": str(timeout)}) if logger.level == logging.DEBUG: logger.debug("return: " + str(res)) diff --git a/pyTigerGraph/pytgasync/pyTigerGraphLoading.py b/pyTigerGraph/pytgasync/pyTigerGraphLoading.py index 72c196c0..74ed7452 100644 --- a/pyTigerGraph/pytgasync/pyTigerGraphLoading.py +++ b/pyTigerGraph/pytgasync/pyTigerGraphLoading.py @@ -161,8 +161,13 @@ async def runLoadingJobWithData(self, data: str, fileTag: str, jobName: str, sep if eol is not None: params["eol"] = eol - res = await self._req("POST", self.restppUrl + "/ddl/" + self.graphname, params=params, data=data, - headers={"RESPONSE-LIMIT": str(sizeLimit), "GSQL-TIMEOUT": str(timeout)}) + if isinstance(data, str): + data = data.encode("utf-8") + res = await self._req("POST", self.restppUrl + "/ddl/" + self.graphname, params=params, data=data, + headers={"Content-Type": "application/x-www-form-urlencoded; Charset=utf-8", "RESPONSE-LIMIT": str(sizeLimit), "GSQL-TIMEOUT": str(timeout)}) + else: + res = await self._req("POST", self.restppUrl + "/ddl/" + self.graphname, params=params, data=data, + headers={"RESPONSE-LIMIT": str(sizeLimit), "GSQL-TIMEOUT": str(timeout)}) if logger.level == logging.DEBUG: logger.debug("return: " + str(res))