|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
源代码
import requests
header = {'User-Agent':'Mozilla/5.0' ,}
url = 'https://fanyi.baidu.com/sug'
def fanyi(value):
key = { 'kw': value}
r = requests.post(url, data = key, headers = header)
result = r.json()
return result
if __name__ == '__main__':
word = input("请输入要翻译的内容: ")
res = fanyi(word)
print(res)
请输入要翻译的内容: china
报错信息:
Traceback (most recent call last):
File "C:/Users/98511/PycharmProjects/pythonProject2/demo.py", line 11, in <module>
res = fanyi(word)
File "C:/Users/98511/PycharmProjects/pythonProject2/demo.py", line 6, in fanyi
r = requests.post(url, data = key, headers = header)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 500, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 453, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\98511\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 997, in _create
raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
在我这台电脑上始终报错,同样的代码在我同学那里就可以正常输出翻译内容
|
|