Wow, thank you so much for replying!
Unfortunately, I'm still struggling to import responses...
If I put requests and urrlib into my folder and put these inside the module:
Code:
from calibre_plugins.kybook3_sync.urllib3 import urllib3
from calibre_plugins.kybook3_sync.requests import requests
Then I get this traceback:
Code:
File "calibre/customize/zipplugin.py", line 192, in exec_module
File "calibre_plugins.kybook3_sync.urllib3.util.connection", line 5, in <module>
from urllib3.exceptions import LocationParseError
ModuleNotFoundError: No module named 'urllib3'
I wonder if I'm not approaching it from the right angle...
Essentially this code doesn't work with calibre:
Code:
def _encode_multipart_formdata(self, fields, files):
limit = '-----------------------------'
num = str(int((datetime.now() - datetime(1970, 1, 1)).total_seconds()))
limit = limit + num
crlf = '\r\n'
lines = []
for (key, value) in fields:
lines.append('--' + limit)
lines.append('Content-Disposition: form-data; name="%s"' % key)
lines.append('')
if isinstance(value,bytes):
lines.append(value.decode())
else:
lines.append(value)
for (key, filename, value) in files:
lines.append('--' + limit)
lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
lines.append('Content-Type: %s' % self._get_content_type(filename))
lines.append('')
if isinstance(value,bytes):
lines.append(value.decode())
else:
lines.append(value)
lines.append('--' + limit + '--')
lines.append('')
body = crlf.join(lines)
content_type = 'multipart/form-data; boundary=%s' % limit
return content_type, body
in python3 it gives an error
Code:
line = ''.join(line.split())
TypeError: sequence item 0: expected str instance, bytes found
I wonder what's the most efficient way to resolve this is... So far I tried
1) Fixing the routine by changing all '' with b'' - didn't work due to me not knowing what's the encoding of a file I'm getting
2) Importing requests - a hassle, possible cross-platform issues
What would you suggest as the 'neatest' and most calibre-like way of uploading a file to a web server that uses simple plain-text authorization?