Answer the question
In order to leave comments, you need to log in
Why can Python wget report http.client.InvalidURL when using login and password?
The task of downloading logs via http for devices that do not know how to syslog, and so on.
http requires mandatory authorization plain-text
In python, I tried to write the following:
import wget
import yaml
with open('config.yml') as c:
config = yaml.safe_load(c)
user = str(config['credentials']['user'])
password = str(config['credentials']['password'])
device = atc78-47-msk
url = 'http://'+ user + ':' + password +'@'+ device +'/US/4/config_trunk.log'
wget.download(url)
Traceback (most recent call last):
File "Programs\Python\Python39\lib\http\client.py", line 871, in _get_hostport
port = int(host[i+1:])
ValueError: invalid literal for int() with base 10: '[email protected]'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 21, in <module>
wget.download('http://admin:[email protected]/US/4/config_trunk.log.log')
File "\venv\lib\site-packages\wget.py", line 526, in download
(tmpfile, headers) = ulib.urlretrieve(binurl, tmpfile, callback)
File "Programs\Python\Python39\lib\urllib\request.py", line 239, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "Programs\Python\Python39\lib\urllib\request.py", line 517, in open
response = self._open(req, data)
File "Programs\Python\Python39\lib\urllib\request.py", line 534, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "Programs\Python\Python39\lib\urllib\request.py", line 1375, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "Programs\Python\Python39\lib\urllib\request.py", line 1315, in do_open
h = http_class(host, timeout=req.timeout, **http_conn_args)
File "Programs\Python\Python39\lib\http\client.py", line 833, in __init__
(self.host, self.port) = self._get_hostport(host, port)
File "Programs\Python\Python39\lib\http\client.py", line 876, in _get_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
http.client.InvalidURL: nonnumeric port: '[email protected]'
Process finished with exit code 1
Answer the question
In order to leave comments, you need to log in
Why use such a strange module?! Use requests - https://docs.python-requests.org/en/latest/
Well, something tells me that you just don't have a 4R-1-ASW device....
import requests
....
r = requests.get('http://' + device +'/US/4/config_trunk.log', auth=('admin', '123456'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question