-
Notifications
You must be signed in to change notification settings - Fork 104
/
get_token.py
47 lines (32 loc) · 1.21 KB
/
get_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
import os
from os import path
import requests
def run():
current_path = os.getcwd() # 获取当前工作目录路径
parent_path = os.path.dirname(current_path) # 获取父目录路径
current_dir = path.dirname(path.abspath(__file__))
credentials_file = path.join(current_dir, 'user.txt')
tokens_file = '/app/ChatGPT-AccessToken-Web/.env.local'
with open(credentials_file, 'r', encoding='utf-8') as f:
credentials = f.read().split('\n')
credentials = [credential.split(',', 1) for credential in credentials]
print(credentials)
username=credentials[0][0]
password=credentials[0][1]
url = "http://PandoraNext:8080/gpt12345/api/auth/login"
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
data = {
'username': username,
'password': password
}
response = requests.request("POST", url, headers=headers, data=data)
access_token = response.json()['access_token']
print(access_token)
with open(tokens_file, 'w', encoding='utf-8') as f:
f.write('OPENAI_API_KEY="')
f.write('{}"\n'.format(access_token))
if __name__ == '__main__':
run()