New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update rates from fixer.io #675 #681
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@@ -45,9 +45,12 @@ def get_params(self): | |||
return {} | |||
|
|||
def get_response(self, **params): | |||
url = self.get_url(**params) | |||
headers = { | |||
"User-Agent": "Mozilla/5.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could get into trouble for faking the User-Agent, not sure. But I'll leave that up to others to scrutinize :)
@@ -15,4 +15,4 @@ def __init__(self, url=settings.FIXER_URL, access_key=settings.FIXER_ACCESS_KEY) | |||
self.access_key = access_key | |||
|
|||
def get_params(self): | |||
return {"access_key": self.access_key} | |||
return {"apikey": self.access_key} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change added? Isn't the fixer api expecting an access_key
parameter?
https://fixer.io/documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Ignat! Since fixer.io does not provide its API through the endpoints described in the documentation, but instead uses APILayer services for this purpose, it was necessary to change the key specifically for APILayer. This is described in the API documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @spaut33 for the quick response. It makes sense, but isn't the apikey
suppose to be included in the headers in that case?
Sorry for the questions but a code I'm working on started failing after upgrading djmoney to 3.1.0 and I'm trying to figure out what's the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works both ways, as a request parameter and as a header. However, I believe that APILayer may not be following the correct convention, as custom fields in headers should start with the "X-" prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Fixed by creating API key through ApiLayer and adding FIXER_URL = "https://api.apilayer.com/fixer/latest"
to my settings.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But apilayer
seems unreliable — getting timeouts accessing the API. Could we maybe send access_key
and apikey
params to suit both APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @fedosov. I've just added the FIXER_URL
to the settings.py
as well. It took me some time to figure that out. Maybe the default should be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a PR so it can work with both APIs
#707
Small fix for #675. Changed get parameter and added 'user-agent' header to avoid 403 error.