requestsで帰ってきた画像をPillowで別の画像に貼り付けようとしたのですが、このコードを実行するとエラーが起きてしまいます。
lang
1from PIL import Image, ImageDraw, ImageFilter 2import requests 3res = requests.get("www.example.com/hoge.png") 4print(res.encoding) # 出力結果: None 5img = Image.open(res.content)
Traceback (most recent call last): File "C:\Users???\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File ".\test.py", line 62, in on_message img = Image.open(res.content) File "C:\Users???\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\Image.py", line 2609, in open fp = builtins.open(filename, "rb") UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
このエラーコードについて調べてみたのですが、出てきた以下の方法を試してもうまくいきませんでした。
res.encoding = res.apparent_encoding
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/10/21 05:14