Repository: ultrabug/py3status

Issue:
error basic auth url encoding
I get the following error when attempting to use basic auth url encoding.

```
$ curl https://user:password@test.com/test.json 
{"some":" data"}

$ cat config 
order += "getjson test"

getjson test {
    url = "https://user:password@test.com/test.json"
    format = "{some}"
    cache_timeout = 300
}

$ py3status --config config --log-file log-file --wm sway
{"version": 1, "click_events": true, "stop_signal": 20}
[[]
,[{"full_text": "getjson test", "color": "#FF0000", "instance": "test", "name": "getjson"}]
^C

$ cat log-file
2019-12-15 13:00:36 INFO ========
2019-12-15 13:00:36 INFO Starting py3status version 3.22 python 3.8.0
2019-12-15 13:00:36 INFO window manager: sway
2019-12-15 13:00:36 INFO config file: config
2019-12-15 13:00:36 INFO modules include paths: []
2019-12-15 13:00:36 INFO loading module "getjson test" from py3status.modules.getjson
2019-12-15 13:00:36 INFO starting module getjson test
2019-12-15 13:00:36 WARNING Instance `getjson test`, user method `getjson` failed (InvalidURL) request.py line 72.
2019-12-15 13:00:36 INFO Traceback
InvalidURL: nonnumeric port: 'password@test.com'
  File "/usr/lib/python3.8/site-packages/py3status/module.py", line 946, in run
    response = method()
  File "/usr/lib/python3.8/site-packages/py3status/modules/getjson.py", line 85, in getjson
    json_data = self.py3.request(self.url).json()
  File "/usr/lib/python3.8/site-packages/py3status/py3.py", line 1318, in request
    return get_http_response()
  File "/usr/lib/python3.8/site-packages/py3status/py3.py", line 1306, in get_http_response
    return HttpResponse(
  File "/usr/lib/python3.8/site-packages/py3status/request.py", line 72, in __init__
    self._response = urlopen(request, data=data, timeout=timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 1360, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/usr/lib/python3.8/urllib/request.py", line 1286, in do_open
    h = http_class(host, timeout=req.timeout, **http_conn_args)
  File "/usr/lib/python3.8/http/client.py", line 1357, in __init__
    super(HTTPSConnection, self).__init__(host, port, timeout,
  File "/usr/lib/python3.8/http/client.py", line 829, in __init__
    (self.host, self.port) = self._get_hostport(host, port)
  File "/usr/lib/python3.8/http/client.py", line 870, in _get_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
```


Discussion:
Hello @CorruptCommit 

This is because `getjson` does not support passing down auth credentials to the request helper.

Other modules using this helper propose login + password configuration options. Would that be cool with you if getjson proposed that as well and handled auth for you?

Resolving patch:
diff --git a/py3status/modules/getjson.py b/py3status/modules/getjson.py
--- a/py3status/modules/getjson.py
+++ b/py3status/modules/getjson.py
@@ -12,7 +12,9 @@
     cache_timeout: refresh interval for this module (default 30)
     delimiter: the delimiter between parent and child objects (default '-')
     format: display format for this module (default None)
+    password: basic auth password information (default None)
     url: specify URL to fetch JSON from (default None)
+    username: basic auth user information (default None)
 
 Format placeholders:
     Placeholders will be replaced by the JSON keys.
@@ -61,7 +63,9 @@ class Py3status:
     cache_timeout = 30
     delimiter = "-"
     format = None
+    password = None
     url = None
+    username = None
 
     class Meta:
         deprecated = {
@@ -82,7 +86,11 @@ def getjson(self):
         """
         """
         try:
-            json_data = self.py3.request(self.url).json()
+            if self.username is not None and self.password is not None:
+                auth = (self.username, self.password)
+            else:
+                auth = None
+            json_data = self.py3.request(self.url, auth=auth).json()
             json_data = self.py3.flatten_dict(json_data, self.delimiter, True)
         except self.py3.RequestException:
             json_data = None


Test patch: