UnicodeCodeError:' Charmap' (仅使用PHP)

发布于 2025-02-13 20:58:12 字数 523 浏览 2 评论 0原文

我有一个想获得“阿拉伯语”价值的输入 我做了此代码

token = soup.find('input', {'name':'EmpName'})['value']
print(token)

,它在终端(CMD)中起作用
但是,每当我尝试用PHP打印输出时,就会给我这个错误。

UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-3: character 
maps to

我使用此PHP代码打印输出,它可以与

<?php echo exec('python q.py 2>&1'); ?>

我尝试添加的

print(token.encode('cp1252'))
print(token.encode('utf-8'))

其他任何内容都无法使用。

I have an input that I want to get the value of in "Arabic"
and I did this code

token = soup.find('input', {'name':'EmpName'})['value']
print(token)

and it works in the terminal ( cmd )

but the real problem that whenever I try to print the output with php it keeps giving me this error.

UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-3: character 
maps to

I used this PHP code to print the output and it works with anything else

<?php echo exec('python q.py 2>&1'); ?>

I tried to add

print(token.encode('cp1252'))
print(token.encode('utf-8'))

didn't work at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十雾 2025-02-20 20:58:12

我通过添加忽略错误并将其编码到UTF-8,然后将其解码到CP1252 CUZ,将其修复

vo = (token.encode('utf-8', errors='ignore'))
print (vo.decode('cp1252', errors='ignore'))

I fixed it by adding ignore errors and encoding it to utf-8 and then decoding it to cp1252 cuz I'm on windows

vo = (token.encode('utf-8', errors='ignore'))
print (vo.decode('cp1252', errors='ignore'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文