InvalidHeader when getting payment_methods
Closed this issue · 9 comments
Python version: 3.7
Library version: 2.1.0
Description
Sending a request through .checkout.payment_methods causes an exception from requests.
Full traceback:
2019-09-20T10:17:46.634599+00:00 app[web.1]: Traceback (most recent call last):
2019-09-20T10:17:46.634601+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
2019-09-20T10:17:46.634602+00:00 app[web.1]: response = self.full_dispatch_request()
2019-09-20T10:17:46.634604+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
2019-09-20T10:17:46.634606+00:00 app[web.1]: rv = self.handle_user_exception(e)
2019-09-20T10:17:46.634607+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
2019-09-20T10:17:46.634609+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2019-09-20T10:17:46.634610+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
2019-09-20T10:17:46.634612+00:00 app[web.1]: raise value
2019-09-20T10:17:46.634613+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
2019-09-20T10:17:46.634614+00:00 app[web.1]: rv = self.dispatch_request()
2019-09-20T10:17:46.634615+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
2019-09-20T10:17:46.634618+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2019-09-20T10:17:46.634621+00:00 app[web.1]: File "/app/app/blueprints/api/routes.py", line 84, in _get_adyen_data
2019-09-20T10:17:46.634622+00:00 app[web.1]: config = adyen.checkout.payment_methods(data)
2019-09-20T10:17:46.634624+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/Adyen/services.py", line 315, in payment_methods
2019-09-20T10:17:46.634625+00:00 app[web.1]: return self.client.call_checkout_api(request, action, **kwargs)
2019-09-20T10:17:46.634626+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/Adyen/client.py", line 454, in call_checkout_api
2019-09-20T10:17:46.634628+00:00 app[web.1]: **kwargs)
2019-09-20T10:17:46.634629+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/Adyen/httpclient.py", line 192, in _requests_post
2019-09-20T10:17:46.634630+00:00 app[web.1]: headers=headers, timeout=timeout)
2019-09-20T10:17:46.634632+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/api.py", line 116, in post
2019-09-20T10:17:46.634633+00:00 app[web.1]: return request('post', url, data=data, json=json, **kwargs)
2019-09-20T10:17:46.634635+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/api.py", line 60, in request
2019-09-20T10:17:46.634636+00:00 app[web.1]: return session.request(method=method, url=url, **kwargs)
2019-09-20T10:17:46.634637+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/sessions.py", line 519, in request
2019-09-20T10:17:46.634638+00:00 app[web.1]: prep = self.prepare_request(req)
2019-09-20T10:17:46.634639+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/sessions.py", line 462, in prepare_request
2019-09-20T10:17:46.634640+00:00 app[web.1]: hooks=merge_hooks(request.hooks, self.hooks),
2019-09-20T10:17:46.634641+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/models.py", line 314, in prepare
2019-09-20T10:17:46.634642+00:00 app[web.1]: self.prepare_headers(headers)
2019-09-20T10:17:46.634643+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/models.py", line 448, in prepare_headers
2019-09-20T10:17:46.634644+00:00 app[web.1]: check_header_validity(header)
2019-09-20T10:17:46.634645+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/requests/utils.py", line 942, in check_header_validity
2019-09-20T10:17:46.634647+00:00 app[web.1]: raise InvalidHeader("Invalid return character or leading space in header: %s" % name)
2019-09-20T10:17:46.634648+00:00 app[web.1]: requests.exceptions.InvalidHeader: Invalid return character or leading space in header: User-Agent
Ok, found out the issue. I used the code for python from the docs, but it turns out you need to specify app name for the client.
It might be worth it replacing these two lines:
adyen = Adyen.Adyen()
adyen.client.xapikey = 'YOUR_X-API-KEY'
With:
adyen = Adyen.Adyen(
app_name='YOUR_APP_NAME',
xapikey='YOUR_X-API-KEY'
)
A pull request has been submitted to fix the issue. The Adyen client should behave as documented. #88
Awesome. App Name should definitely be optional, since it can be anything (from what I can see) and only affects the UserAgent header.
We're having the same issue as well, should the app name be mandatory ? if it is, this should be documented correctly.
@Ishrock Thank for for this PR! I see that it is closed, do you know if it has been merged to any production ready version or not yet?
Hello @golyalpha,
We created an internal ticket and we are going to pick it up as soon as possible. For now you can pass a dummy app_name so you can continue with the integration.
kind regards,
Alexandros
I've already moved on from this issue, setting my own app_name for the client library. I did initially recommend just changing the documentation to mention that one should do that.
This issue is fixed in version 3.0.0