import logging.handlers
import os
import sys
-import urllib
-import urllib2
+import urllib.request, urllib.parse, urllib.error
+import urllib.request, urllib.error, urllib.parse
import fireinfo
for line in json.dumps(profile, sort_keys=True, indent=4).splitlines():
logging.debug(line)
- request = urllib2.Request(PROFILE_URL % profile,
- data = urllib.urlencode({"profile" : json.dumps(profile)}),
+ request = urllib.request.Request(PROFILE_URL % profile,
+ data = urllib.parse.urlencode({"profile" : json.dumps(profile)}),
)
request.add_header("User-Agent", "fireinfo/%s" % fireinfo.__version__)
if proxy["user"] and proxy["pass"]:
prx_auth_string = "http://%s:%s@%s/" % (proxy["user"], proxy["pass"], proxy["host"])
- proxy_handler = urllib2.ProxyHandler({'http': prx_auth_string, 'https': prx_auth_string})
- auth = urllib2.HTTPBasicAuthHandler()
- opener = urllib2.build_opener(proxy_handler, auth, urllib2.HTTPHandler)
- urllib2.install_opener(opener)
+ proxy_handler = urllib.request.ProxyHandler({'http': prx_auth_string, 'https': prx_auth_string})
+ auth = urllib.request.HTTPBasicAuthHandler()
+ opener = urllib.request.build_opener(proxy_handler, auth, urllib.request.HTTPHandler)
+ urllib.request.install_opener(opener)
else:
request.set_proxy(proxy["host"], "http")
request.set_proxy(proxy["host"], "https")
try:
- urllib2.urlopen(request, timeout=60)
- except (urllib2.HTTPError, urllib2.URLError), e:
+ urllib.request.urlopen(request, timeout=60)
+ except (urllib.error.HTTPError, urllib.error.URLError) as e:
reason = "Unknown reason"
- if isinstance(e, urllib2.HTTPError):
+ if isinstance(e, urllib.error.HTTPError):
reason = "%s" % e
- elif isinstance(e, urllib2.URLError):
+ elif isinstance(e, urllib.error.URLError):
reason = e.reason
logging.error("Profile was not sent propertly: %s" % reason)
# it contains no information and may confuse people.
del profile["private_id"]
- print json.dumps(profile, sort_keys=True, indent=4)
+ print(json.dumps(profile, sort_keys=True, indent=4))
return 0
if "--secret-id" in sys.argv:
- print system.secret_id
+ print(system.secret_id)
return 0
if "--hardware-string" in sys.argv:
- print system._unique_id
+ print(system._unique_id)
return 0
if "--public-id" in sys.argv:
- print system.public_id
+ print(system.public_id)
return 0
if not os.path.exists(ENABLED_FILE):
try:
send_profile(profile)
- except urllib2.URLError:
+ except urllib.error.URLError:
return 1
return 0