鱼C论坛

 找回密码
 立即注册
查看: 2266|回复: 2

[已解决]一个叫HTTP Error 500: Internal Server Error的BUG

[复制链接]
发表于 2023-1-25 20:02:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
刚刚开始学习Python,看了一个视频教程之后按照教程尝试,
但是结果出现了urllib.error.HTTPError: HTTP Error 500: Internal Server Error,
具体实现的功能是利用post请求百度翻译的详细翻译
代码如下:
import urllib.request
import urllib.parse
import json
url='https://fanyi.baidu.com/v2transapi?from=en&to=zh'

headers={
    'Accept':' */*',
    # 'Accept-Encoding':' gzip, deflate, br',
    'Accept-Language':' zh-CN,zh;q=0.9',
    'Connection':' keep-alive',
    'Content-Length':' 136',
    'Content-Type':' application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'BIDUPSID=E93B339658BDFE321960B93B70A9EAFD; PSTM=1674224026; BAIDUID=E93B339658BDFE322A893B54A7CDEDEA:FG=1; BAIDUID_BFESS=E93B339658BDFE322A893B54A7CDEDEA:FG=1; ZFY=MSuAnxENbgH:AEqQwSOP2FlC0:AruCTwf:BbacXBcV58ZM:C; APPGUIDE_10_0_2=1; FANYI_WORD_SWITCH=1; REALTIME_TRANS_SWITCH=1; HISTORY_SWITCH=1; SOUND_PREFER_SWITCH=1; SOUND_SPD_SWITCH=1; ariaDefaultTheme=undefined; RT="z=1&dm=baidu.com&si=e5hb03k1fsn&ss=ld8xlz6v&sl=6&tt=33f&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=gco&ul=vl8&hd=vm0"; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; SEARCH_MARKET_ABG_URL=http%3A//abg.baidu.com/ndoffhome/search%3Fquery%3D%25E7%259C%258B%25E4%25B9%25A6%26fileType%3D%26fr%3Dlaunch_ad%26SS-bdtg24%3D%26utm_source%3Dbdss-WD%26utm_medium%3Dcpc%26utm_account%3DSS-bdtg24%26utm_brand%3Dabg%26e_creative%3D68600065689%26e_keywordid%3D536869508575%26bd_vid%3D10644333436569472536; BDRCVFR[za_m8Iw8qNT]=mk3SLVN4HKm; H_PS_PSSID=; BA_HECTOR=al84a52h050h052la50485411ht174b1k; PSINO=1; delPer=0; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1674529315,1674548995,1674549837,1674615967; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1674615967; ab_sr=1.0.1_MTcyOTg0NzA4YzA3NWJiYzFlYmUwM2E5ZGEwNmZkNjkwMjczNDVlNzgzMzNiZTc4ZDc1ODQyYzg4YTI5NDY2MzBkYjJjZTFlMDA1M2Q3Y2Y3M2FiYzM5OTkyYTgyZDdhZmE4OTA1MzNhZGE4ZWIyNTczNjQ5NmQ5ZjliMzRhNWNiZTZlNmMyZWFjZjE4ZjZiYjdiMTc0N2E2MjY4NDUxMg==',
    'Host':' fanyi.baidu.com',
    'Origin': 'https://fanyi.baidu.com',
    'Referer': 'https://fanyi.baidu.com/?aldtype=16047',
    'sec-ch-ua':' "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
    'sec-ch-ua-mobile':' ?0',
    'sec-ch-ua-platform':' "Windows"',
    'Sec-Fetch-Dest':' empty',
    'Sec-Fetch-Mode':' cors',
    'Sec-Fetch-Site':' same-origin',
    'User-Agent':' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
    'X-Requested-With':' XMLHttpRequest',
}

data={
    'from':' en',
    'to':' zh',
    'query':' spider',
    'simple_means_flag':' 3',
    'sign':' 63766.268839',
    'token':' 53b42a52057b8a1818a9497203c34625',
    'domain':' common',
}

data=urllib.parse.urlencode(data).encode('utf-8')

request=urllib.request.Request(url,data,headers)

response=urllib.request.urlopen(request)

content=response.read().decode('utf-8')

print(content)
obj=json.loads(content)
print(obj)

报出的错误是:
Traceback (most recent call last):
  File "D:\桌面文件夹\Python基础\pythonDemo3.py", line 234, in <module>
    response=urllib.request.urlopen(request)
  File "D:\Python\Python36\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "D:\Python\Python36\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "D:\Python\Python36\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "D:\Python\Python36\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)
  File "D:\Python\Python36\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "D:\Python\Python36\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error
最佳答案
2023-1-25 21:18:46
baidu网站早更新了。过期了。知道原理就行

论坛 搜 百度翻译 应该有最新的代码范例
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-25 21:18:46 | 显示全部楼层    本楼为最佳答案   
baidu网站早更新了。过期了。知道原理就行

论坛 搜 百度翻译 应该有最新的代码范例
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-26 12:26:14 | 显示全部楼层
ba21 发表于 2023-1-25 21:18
baidu网站早更新了。过期了。知道原理就行

论坛 搜 百度翻译 应该有最新的代码范例

感谢提醒
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-16 08:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表