问题遇到的现象和发生背景
我用百度API的翻译平台,用他官网提供的代码运行,结果报错。
问题相关代码,请勿粘贴截图
appid =
secretKey =
url_baidu =
def translateBaidu(text, f='zh', t='en'):
salt = random.randint(32768, 65536)
sign = appid + text + str(salt) + secretKey
sign = hashlib.md5(sign.encode()).hexdigest()
url = url_baidu + '?appid=' + appid + '&q=' + urllib.parse.quote(text) + '&from=' + f + '&to=' + t + \
'&salt=' + str(salt) + '&sign=' + sign
response = urllib.request.urlopen(url)
content = response.read().decode('utf-8')
data = json.loads(content)
result = str(data['trans_result'][0]['dst'])
print(result)