-
Notifications
You must be signed in to change notification settings - Fork 32
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
Use requests for HTTP/HTTPS calls in library #240
Changes from all commits
6e86e34
192b43a
5ae046a
c889c49
573bda8
16dd113
4f8d9fb
0c01a0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,16 +6,14 @@ | |||||||||||
""" | ||||||||||||
|
||||||||||||
from future import standard_library | ||||||||||||
standard_library.install_aliases() | ||||||||||||
from builtins import str | ||||||||||||
from builtins import object | ||||||||||||
from omero_version import omero_version | ||||||||||||
|
||||||||||||
import platform | ||||||||||||
import logging | ||||||||||||
import urllib.request, urllib.error, urllib.parse | ||||||||||||
import urllib.request, urllib.parse, urllib.error | ||||||||||||
import socket | ||||||||||||
import requests | ||||||||||||
standard_library.install_aliases() | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joshmoore Can we get rid of this? Sounds like it's only required for Python 2.7 support https://python-future.org/quickstart.html#to-convert-existing-python-3-code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @manics: Thought about doing that here but wanted to keep the changes to what were required to do the job. I saw some other weird stuff like this when doing my review of omero-py/src/omero/util/sessions.py Lines 38 to 42 in fa8d3b9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Don't see why not. |
||||||||||||
|
||||||||||||
|
||||||||||||
class UpgradeCheck(object): | ||||||||||||
|
@@ -47,8 +45,8 @@ class UpgradeCheck(object): | |||||||||||
""" | ||||||||||||
|
||||||||||||
# | ||||||||||||
# Default timeout is 3 seconds. | ||||||||||||
# * http://docs.python.org/2/library/socket.html#socket.setdefaulttimeout | ||||||||||||
# our default timeout to use for requests; package default is no timeout | ||||||||||||
# * https://requests.readthedocs.io/en/master/user/quickstart/#timeouts | ||||||||||||
# | ||||||||||||
DEFAULT_TIMEOUT = 6.0 | ||||||||||||
|
||||||||||||
|
@@ -102,7 +100,7 @@ def getOSVersion(self): | |||||||||||
platform.mac_ver()[0]) | ||||||||||||
else: | ||||||||||||
version = platform.platform() | ||||||||||||
except: | ||||||||||||
except Exception: | ||||||||||||
version = platform.platform() | ||||||||||||
return version | ||||||||||||
|
||||||||||||
|
@@ -129,20 +127,13 @@ def run(self): | |||||||||||
params["python.version"] = platform.python_version() | ||||||||||||
params["python.compiler"] = platform.python_compiler() | ||||||||||||
params["python.build"] = platform.python_build() | ||||||||||||
params = urllib.parse.urlencode(params) | ||||||||||||
|
||||||||||||
old_timeout = socket.getdefaulttimeout() | ||||||||||||
try: | ||||||||||||
socket.setdefaulttimeout(self.timeout) | ||||||||||||
full_url = "%s?%s" % (self.url, params) | ||||||||||||
request = urllib.request.Request(full_url) | ||||||||||||
request.add_header('User-Agent', self.agent) | ||||||||||||
self.log.debug("Attempting to connect to %s" % full_url) | ||||||||||||
response = urllib.request.urlopen(request) | ||||||||||||
result = response.read() | ||||||||||||
finally: | ||||||||||||
socket.setdefaulttimeout(old_timeout) | ||||||||||||
|
||||||||||||
headers = {'User-Agent': self.agent} | ||||||||||||
request = requests.get( | ||||||||||||
self.url, headers=headers, params=params, | ||||||||||||
timeout=self.DEFAULT_TIMEOUT | ||||||||||||
) | ||||||||||||
result = request.text | ||||||||||||
except Exception as e: | ||||||||||||
self.log.error(str(e), exc_info=0) | ||||||||||||
self._set(None, e) | ||||||||||||
|
@@ -152,5 +143,5 @@ def run(self): | |||||||||||
self.log.info("no update needed") | ||||||||||||
self._set(None, None) | ||||||||||||
else: | ||||||||||||
self.log.warn("UPGRADE AVAILABLE:" + result.decode('utf-8')) | ||||||||||||
self._set(result.decode('utf-8'), None) | ||||||||||||
self.log.warn("UPGRADE AVAILABLE:" + result) | ||||||||||||
self._set(result, None) |
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.
Are you intentionally keeping
pyopenssl
as an optional dependency? It's not installed by default:https://github.com/psf/requests/blob/2d39c0db054e158767ab4a755476844fe40787e7/setup.py#L105
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.
Yes, definitely intentional. Don't want to force it on people if they don't need/want it.