''' Author: 20004@163.com Date: 2022-10-13 11:05:27 LastEditTime: 2022-10-13 11:07:57 LastEditors: 20004@163.com Description: FilePath: \PythonCode\website5\百度翻译11.py 可以输入预定的版权声明、个性签名、空行等 ''' import http.client import hashlib import urllib import random import json appid = '2021343400667671' secretKey = 'sekMHy545WSNTE8Q' httpClient = None myurl = '/api/trans/vip/fieldtranslate' fromLang = 'auto' toLang = 'bur' salt = random.randint(32768, 65536) q= '真的' domain = 'medicine' sign = appid + q + str(salt) + domain + secretKey sign = hashlib.md5(sign.encode()).hexdigest() myurl = myurl + '?appid=' + appid + '&q=' + urllib.parse.quote(q) + '&from=' + fromLang + '&to=' + toLang + '&salt=' + str(salt) + '&domain=' + domain + '&sign=' + sign try: httpClient = http.client.HTTPConnection('api.fanyi.baidu.com') httpClient.request('GET', myurl) response = httpClient.getresponse() result_all = response.read().decode("utf-8") result = json.loads(result_all) print (result) except Exception as e: print (e) finally: if httpClient: httpClient.close()