Skip to content

specify user-agent in tmy3 remote request #494

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

Merged
merged 1 commit into from
Jun 26, 2018
Merged

Conversation

wholmgren
Copy link
Member

@wholmgren wholmgren commented Jun 25, 2018

  • Closes NREL TMY server rejecting python requests #493
  • Fully tested. Added and/or modified tests to ensure correct behavior for all reasonable inputs. Tests must pass on the TravisCI and Appveyor testing services.
  • Code quality and style is sufficient. Passes git diff upstream/master -u -- "*.py" | flake8 --diff and/or landscape.io linting service.
  • New code is fully documented. Includes sphinx/numpydoc compliant docstrings and comments in the code where necessary.
  • Updates entries to docs/sphinx/source/api.rst for API changes.
  • Adds description and name entries in the appropriate docs/sphinx/source/whatsnew file for all changes.

@wholmgren wholmgren added the bug label Jun 25, 2018
@wholmgren wholmgren added this to the 0.6.0 milestone Jun 25, 2018
@markcampanelli
Copy link
Contributor

@wholmgren Thanks for tracking this one down.

@wholmgren
Copy link
Member Author

@cwhanse any concerns here? if not, please go ahead and "squash and merge".

response = urlopen(filename)
if filename.startswith('http'):
request = Request(filename, headers={'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) '
Copy link
Member

Choose a reason for hiding this comment

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

Does any user agent work here, or does it need to match the user's browser and platform? If the latter then we need to test this fix on multiple OS.

Copy link
Member Author

Choose a reason for hiding this comment

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

No and no.

By default, Python's urllib specifies a user-agent that is "Python-urllib/x.y" where x.y is the version. https://docs.python.org/3/howto/urllib2.html This user agent is no longer allowed. I am guessing most user agents that identify themselves as scripts are now blocked.

The automated tests run on linux and windows (not mac), and they pass on this PR (note that they currently fail on the master). I don't think that the server has any way of knowing that our script is pretending to be a browser unless it does something smarter (e.g. sees that the requests are coming from IPs associated with travis-ci and appveyor).

Copy link
Member

Choose a reason for hiding this comment

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

Satisfies me.

@cwhanse cwhanse merged commit e6aa17c into pvlib:master Jun 26, 2018
@wholmgren wholmgren deleted the tmyremote branch June 26, 2018 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants