如何修复Python API编码以创建或保存这些符号&#'?

2024-04-20 03:28:43 发布

您现在位置:Python中文网/ 问答频道 /正文

对不起,我在Python中创建了用于API的def。可以保存或创建包含符号的任何字符

enter image description here

使用这样的编码:

text = str(bbas + l).encode('UTF-8')
hash_md5 = hashlib.md5(text).hexdigest()
md5_encode = hash_md5.encode('UTF-8')
hash_sha1 = hashlib.sha1(md5_encode).hexdigest()
location_source = hash_sha1[0:6]

但除了这些符号&;#' enter image description hereenter image description here

如何修复解析数据以接受符号的代码? 你好,福齐


Tags: textapi编码def符号hash字符sha1
1条回答
网友
1楼 · 发布于 2024-04-20 03:28:43

添加到URL的参数应该是URL编码的。python3使用urllib.parse.quote,python2使用urllib.urlencode

如评论中所述,最好不要对通过API接收的数据使用eval(),而是使用类似JSON的东西对其进行序列化

相关问题 更多 >