Задача загрузки логов по http для устройств не умеющих syslog и прочее.
по http требуется обязательная авторизация plain-text
На python попробовал написать следующее:
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)
получаю ошибку парсига, пробовал в лоб кормить строку - ""
http://admin:7513456@atc78-47-msk-1/US/4/config_tr..."" , не хочет принимать.
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: '7513456@atc78-47-msk'
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:7513456@atc78-47-msk/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: '7513456@atc78-47-msk'
Process finished with exit code 1
P.S.
Обычный линуксовый wget прекрасно работает.