Skip to content
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

Merged
merged 1 commit into from Aug 26, 2022
Merged

Conversation

spaut33
Copy link
Contributor

@spaut33 spaut33 commented Jul 24, 2022

Small fix for #675. Changed get parameter and added 'user-agent' header to avoid 403 error.

furins added a commit to furins/django-money that referenced this pull request Aug 7, 2022
Copy link
Contributor

@benjaoming benjaoming left a 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",
Copy link
Contributor

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 :)

@benjaoming benjaoming merged commit 94f2795 into django-money:main Aug 26, 2022
@@ -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}
Copy link

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

Copy link
Contributor Author

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.

Copy link

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ignat14 @fedosov Thank you for your comments. I updated the issue

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants