couldn't find a suitable meme! try again. asyncio error?
bobpaul opened this issue · comments
Description
Meme generator plugin never seems to return any memes. Log shows an error with asyncio.
Output of /bot version
Bot Version: 3.0.0-beta
Python Version: 3.6.4
- aiohttp 2.3.9
- appdirs 1.4.3
- emoji 0.4.5
- hangups 0.4.4
- telepot 12.5
Expected behaviour
An image should be added to the hangout. It's my understanding that even without search terms it should find a random meme.
Actual behaviour
The bot replies "couldn't find a suitable meme! try again"
Steps to reproduce:
- /bot addplugin image.image_memegenerator
- /bot meme buddy the elf
- /bot meme minions
- /bot meme
Log output
2018-01-23 19:32:33 INFO event: eid/dt: 7-H0Z7-CYnf8bmaYj4RnPu/2018-01-23 19:32:33
2018-01-23 19:32:33 INFO event: cid/cn: UgzZ3qyB6fqO1d9cE_N4AaABAQ/Paul Klapperich
2018-01-23 19:32:33 INFO event: c/g/un: 115263783215753353917/115263783215753353917/Paul Klapperich
2018-01-23 19:32:33 INFO event: len/tx: 17//bot meme minions
2018-01-23 19:32:33 ERROR asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f213cbc10f0>
2018-01-23 19:32:34 ERROR plugins.image.image_memegenerator: FAILED TO RETRIEVE MEME
Traceback (most recent call last):
File "/home/bobpaul/.slack/hangoutsbot/hangupsbot/plugins/image/image_memegenerator.py", line 39, in meme
if len(results['result']) > 0:
KeyError: 'result'
2018-01-23 19:32:34 INFO event: eid/dt: 7-H0Z7-CYnf8bmaYpvPkS-/2018-01-23 19:32:33
2018-01-23 19:32:34 INFO event: cid/cn: UgzZ3qyB6fqO1d9cE_N4AaABAQ/Paul Klapperich
2018-01-23 19:32:34 INFO event: c/g/un: 112702753819980450357/112702753819980450357/Fargo Enlightened
2018-01-23 19:32:34 INFO event: len/tx: 40/couldn't find a suitable meme! try again
$ http -b 'http://version1.api.memegenerator.net/Instances_Search?q=test&pageIndex=0&pageSize=25'
{
"errorMessage": "Object reference not set to an instance of an object.",
"success": false,
"warning": "The [apiKey] parameter is missing. Soon API access will only be allowed with an API key. Get your API key at https://memegenerator.net/api."
}
Looks like Meme Generator's API may be borked.
Apparently they're also turning off unauthenticated access to most of their APIs. Their docs suggest you can just add ?apiKey=<key>
to the URL for this one, though that doesn't fix the error, just the warning.
Yeah I tried with an API key but I still get the error:
{"success":false,"warning":null,"errorMessage":"Object reference not set to an instance of an object."}
I guess the API is broken, too bad :/
Now it seems another problem is present
2018-02-01 15:04:27 ERROR plugins.image.image_memegenerator: FAILED TO RETRIEVE MEME
Traceback (most recent call last):
File "/code/hangoutsbot/hangupsbot/plugins/image/image_memegenerator.py", line 42, in meme
instanceImageUrl = random.choice(results['result'])['instanceImageUrl']
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 472, in open
response = meth(req, response)
File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.5/urllib/request.py", line 510, in error
return self._call_chain(*args)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
Following
image_data = urllib.request.urlopen(instanceImageUrl)
Needs to be changed to
req = Request(instanceImageUrl, headers={'User-Agent': 'Mozilla/5.0'})
image_data = urlopen(req).read()
And that solves the problem, based on this comment.
Right, User-Agent seems to be required now or you get a 403 error.
I did the same on my side yesterday to fix the problem.
Any idea to implement the apiKey as a param? Put it in the config.json maybe?
@Ig0r-M I'm wondering if we should do a PR for the apiKey part and the User Agent fix. It seems the repo is not maintained (last commit 11 months ago).
@renshuki should we do in this repo(not sure if it would be merged) or i can create a public repo and create PR for that and merge then you can retest to see if problem persist or create new PR and i would analyse.
This is how I fixed it:
https://github.com/renshuki/hangoutsbot/tree/fix-memegenerator-user-agent
It seems you can still use the API even if you haven't an API key.
@renshuki i am new to Python but would like to make a similar plugin only for youtube instead of meme generator, can you help?
It seems you can still use the API even if you haven't an API key.
@renshuki: The warning provided by the API response is fairly clear:
Soon API access will only be allowed with an API key. Get your API key at https://memegenerator.net/api.
It will work for now, but don't be surprised if they later change the API to reject anonymous access.
@Ig0r-M You should create a new issue for the plugin you want to make and check out the Youtube API. Neither I am, I'm Ruby dev :/
@OllieTerrance Yes, this need some improvements to add the API key in the config file.
why not apply this fix?
https://github.com/renshuki/hangoutsbot/tree/fix-memegenerator-user-agent
currently the memegenerator plugin is broken and it would fix it
the api key config can be added later if needed
@Veenkar Unfortunately I don't think the repo is still maintained.
As v3 is now default, the above fix is now in the latest release.