tasmota / decode-config

Backup/restore and decode configuration tool for Tasmota
GNU Lesser General Public License v3.0
211 stars 32 forks source link

Invalid URL: file path occasionally converted to URL #35

Closed hacker-h closed 2 years ago

hacker-h commented 2 years ago

Describe the bug Occasionally the absolute file path passed to decode-config is converted to a URL. /tmp/tasmota01.local.dmp => http:///tmp/tasmota01.local.dmp/dl

To Reproduce Steps to reproduce the behavior: Run decode-config many times on a file, e.g.:

decode-config -s /tmp/tasmota01.local.dmp

> 95% of the time this works fine however occasionally it yields this error:

Traceback (most recent call last):
File "/usr/local/bin/decode-config", line 5207, in <module>
  CONFIG['encode'] = pull_tasmotaconfig(ARGS.device, ARGS.port, username=ARGS.username, password=ARGS.password)
File "/usr/local/bin/decode-config", line 3198, in pull_tasmotaconfig
  _, body = get_tasmotaconfig('dl', host, port, username, password, contenttype='application/octet-stream')
File "/usr/local/bin/decode-config", line 3133, in get_tasmotaconfig
  res = requests.get(url, auth=auth)
File "/home/backuper/.local/lib/python3.9/site-packages/requests/api.py", line 75, in get
  return request('get', url, params=params, **kwargs)
File "/home/backuper/.local/lib/python3.9/site-packages/requests/api.py", line 61, in request
  return session.request(method=method, url=url, **kwargs)
File "/home/backuper/.local/lib/python3.9/site-packages/requests/sessions.py", line 528, in request
  prep = self.prepare_request(req)
File "/home/backuper/.local/lib/python3.9/site-packages/requests/sessions.py", line 456, in prepare_request
  p.prepare(
File "/home/backuper/.local/lib/python3.9/site-packages/requests/models.py", line 316, in prepare
  self.prepare_url(url, params)
File "/home/backuper/.local/lib/python3.9/site-packages/requests/models.py", line 393, in prepare_url
  raise InvalidURL("Invalid URL %r: No host supplied" % url)
requests.exceptions.InvalidURL: Invalid URL 'http:///tmp/tasmota01.local.dmp/dl': No host supplied

Expected behavior decode-config should behave always the same

Version Information (please complete the following information):

$ /usr/local/bin/decode-config -VV
decode-config v9.5.0 [af097d6] by Norbert Richter <nr@prsolution.eu>

Script:   decode-config
Python:   3.9.5
Platform: Linux-5.11.0-37-generic-x86_64-with - x86_64
OS:       Linux 5.11.0-37-generic #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021
Time:     2021-10-08 19:11:46

Additional context Add any other context about the problem here.

curzon01 commented 2 years ago

issue also using current dev 9.5.0.9 of decode-config?

hacker-h commented 2 years ago

Yes, just reproduced it with latest dev commit: https://github.com/tasmota/decode-config/commit/ced97163474f0e13b697213a636a826b09623cb4 btw you might want to force push the commit message v9.2.0.9 => v9.5.0.9

curzon01 commented 2 years ago

Issue cames up if the file '/tmp/tasmota01.local.dmp' does not exists, that's an OS issue, Why this sometimes happens on your system I don't know. I will catch the error and issue a meaningful message.

To prevent this, use the obsolete parameter --file for files only because -s try to find out the source type automatically and if the file you give is reported as not existing from your OS this results in assuming it's an url.

hacker-h commented 2 years ago

Makes perfectly sense, thank you