Uploading snoo/icon fails with IMAGE_ERROR
TheVexedGerman opened this issue · 6 comments
Describe the bug
Trying to upload a new Snoo or icon to a subreddit fails with an asyncpraw.exceptions.RedditAPIException: IMAGE_ERROR: 'Invalid image or general image error'
To Reproduce
Steps to reproduce the behavior:
- Create the subreddit object
- Call the upload_header/upload_mobile_icon on the subreddit moderation stylesheet with the path given
Expected behavior
The expected behavior is that the image would be uploaded and applied to the subreddit styling.
Code/Logs
Log:
Traceback (most recent call last):
File "C:\Users\User\Documents\Git\bot\cogs\reddit_tools.py", line 312, in update_image_executor
await sub.stylesheet.upload_mobile_icon(path_to_image)
File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\asyncpraw\models\reddit\subreddit.py", line 3831, in upload_mobile_icon
return await self._upload_image(image_path, {"upload_type": "icon"})
File "C:\Users\User\AppData\Roaming\Python\Python38\site-packages\asyncpraw\models\reddit\subreddit.py", line 3486, in _upload_image
raise RedditAPIException([[error_type, error_value, None]])
asyncpraw.exceptions.RedditAPIException: IMAGE_ERROR: 'Invalid image or general image error'
async def update_image_executor(self, ctx, path_to_image):
sub = await self.areddit.subreddit(SUBREDDIT)
await sub.stylesheet.upload_mobile_icon(path_to_image)
## Equivalent praw code that works with the same parameters given
# sub = self.reddit.subreddit(SUBREDDIT)
# sub.stylesheet.upload_mobile_icon(path_to_image)
System Info
- OS: Windows 10 2004
- Python: 3.8.6
- Async PRAW Version: 7.1.1
I am not able to reproduce this bug with the test case here:
asyncpraw/tests/integration/models/reddit/test_subreddit.py
Lines 2160 to 2167 in dcaa6a2
If you upload the file I can dig into this a bit deeper tomorrow.
After taking another look and using your test case as a template having the file in the same folder it works, so it appears to be something with a subfolder and relative paths. I have the image in a subfolder called data so data/snoo.png
.
Further testing under Windows with a Windows style path string passed data\snoo.png
shows it does work, but under Linux (Ubuntu 18.04) the both the Windows style path with backslashes Unix style path with a forward slash still fail.
Addendum: Trying to use an absolute path after resolving it with os.path.abspath() under Linux also fails.
So I did some further testing and it seems this issue only occurs with Python 3.8, with both Python 3.7 and 3.9 working fine.
I wasn't able to reproduce this bug with this environment:
System Info
- OS: macOS 11.1 (20C69)
- Python: 3.8.7
- Async PRAW Version: 7.1.1
I ran this code:
from asyncprawcore import Requestor
import json
class JSONDebugRequestor(Requestor):
async def request(self, *args, **kwargs):
response = await super().request(*args, **kwargs)
print(json.dumps(await response.json(), indent=4))
return response
async def main():
async with asyncpraw.Reddit(requestor_class=JSONDebugRequestor, **settings) as reddit:
sub = await reddit.subreddit('LilSpaz')
await sub.stylesheet.upload_mobile_icon('../asyncpraw/tests/integration/files/icon.jpg')
and got this output:
{
"errors": [],
"img_src": "https://b.thumbs.redditmedia.com/9YfWue0XL2CLyD4j34JgSSdm3g-zUFcUcysD9zXV41s.jpg",
"errors_values": []
}
Could you clone asyncpraw and try the above please?
After slightly changing your example code to use my credentials, sub, and starting a loop to run async in I got:
{
"errors": [
"IMAGE_ERROR"
],
"img_src": "",
"errors_values": [
"Invalid image or general image error"
]
}
Traceback (most recent call last):
loop.run_until_complete(main())
File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File ".\asnycprawtest.py", line 18, in main
await sub.stylesheet.upload_mobile_icon('../asyncpraw/tests/integration/files/icon.jpg')
File "C:\Users\User\Documents\Git\asyncpraw\asyncpraw\models\reddit\subreddit.py", line 4010, in upload_mobile_icon
return await self._upload_image(image_path, {"upload_type": "icon"})
File "C:\Users\User\Documents\Git\asyncpraw\asyncpraw\models\reddit\subreddit.py", line 3661, in _upload_image
raise RedditAPIException([[error_type, error_value, None]])
asyncpraw.exceptions.RedditAPIException: IMAGE_ERROR: 'Invalid image or general image error'
System Info
- OS: Windows 10 Pro (19041.804)
- Python: 3.8.7
- Async PRAW Version: commit 9aa6651
I'll just close this as it appears I'm the only one with this issue and I just moved to Python 3.9 to avoid it entirely.