#这是一个python翻译器
import requests
def main():
try:
while 1:
word = input('请输入翻译的内容:')
url = 'https://fanyi.youdao.com/'
data = {'i': word, 'doctype':'json'}
header = {'User-Agent':' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}
response = requests.post(url, data=data, headers = header)
print(response.json()['translateResult'][0][0]['tgt'])
input()
这是结果:
请输入翻译的内容:a
requests.exceptions.InvalidHeader: Invalid return character or leading space in header: User-Agent
#这里就不知道是什么地方错了