Skip to content

Commit 8d37d6b

Browse files
authored
Merge pull request #131 from taosdata/fix/sunpeng/TS-2701-fix-rest-and-ws-for-cloud
fix: fix rest and ws for cloud
2 parents 707f0d1 + ea5d63c commit 8d37d6b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

taos-ws-py/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ fn connect(
263263
dsn.protocol = Some(scheme.extract::<String>()?);
264264
}
265265
} else if let Some(native) = args.get_item("native") {
266-
_ = native;
266+
let _ = native;
267267
} else if dsn.protocol.is_none() {
268268
dsn.protocol.replace("ws".to_string());
269269
}
270270

271-
let host = args.get_item("ip").or(args.get_item("database"));
271+
let host = args.get_item("host").or(args.get_item("ip"));
272272
let port = args.get_item("port");
273273
match (host, port) {
274274
(Some(host), Some(port)) => {
@@ -304,6 +304,7 @@ fn connect(
304304
{
305305
dsn.set(key.extract::<&str>()?, value.extract::<&str>()?);
306306
}
307+
dsn.addresses.push(addr);
307308
}
308309

309310
let builder =

taosrest/sqlalchemy.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ class AlchemyRestConnection:
99
Error = taosrest.Error
1010

1111
def connect(self, **kwargs):
12-
host = kwargs["host"] if "host" in kwargs else "localhost"
13-
port = kwargs["port"] if "port" in kwargs else "6041"
12+
host = kwargs["host"] if "host" in kwargs else None
13+
port = kwargs["port"] if "port" in kwargs else None
1414
user = kwargs["username"] if "username" in kwargs else "root"
1515
password = kwargs["password"] if "password" in kwargs else "taosdata"
1616
database = kwargs["database"] if "database" in kwargs else None
17-
url = f"http://{host}:{port}"
18-
return taosrest.connect(url=url, user=user, password=password, database=database)
17+
token = kwargs["token"] if "token" in kwargs else None
18+
19+
if not host and not port:
20+
host = 'localhost'
21+
port = 6041
22+
if not host:
23+
host = 'localhost'
24+
25+
url = f"http://{host}"
26+
if port:
27+
url += f':{port}'
28+
return taosrest.connect(url=url, user=user, password=password, database=database, token=token)
1929

2030

2131
class TaosRestDialect(default.DefaultDialect):

0 commit comments

Comments
 (0)