asciinema / asciinema

Terminal session recorder 📹

Home Page:https://asciinema.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: Invalid header value b'Basic <ConsumerKey>', error when uploading the local cast

mochadwi opened this issue · comments

I'm trying to upload the local cast, but below error is thrown instead.

Here's the error.

Traceback (most recent call last):
  File "/usr/local/Cellar/asciinema/2.0.2/libexec/bin/asciinema", line 11, in <module>
    load_entry_point('asciinema==2.0.2', 'console_scripts', 'asciinema')()
  File "/usr/local/Cellar/asciinema/2.0.2/libexec/lib/python3.7/site-packages/asciinema/__main__.py", line 131, in main
    code = command.execute()
  File "/usr/local/Cellar/asciinema/2.0.2/libexec/lib/python3.7/site-packages/asciinema/commands/upload.py", line 14, in execute
    result, warn = self.api.upload_asciicast(self.filename)
  File "/usr/local/Cellar/asciinema/2.0.2/libexec/lib/python3.7/site-packages/asciinema/api.py", line 40, in upload_asciicast
    password=self.install_id
  File "/usr/local/Cellar/asciinema/2.0.2/libexec/lib/python3.7/site-packages/asciinema/urllib_http_adapter.py", line 76, in post
    response = urlopen(request)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1244, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1285, in _send_request
    self.putheader(hdr, value)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1222, in putheader
    raise ValueError('Invalid header value %r' % (values[i],))
ValueError: Invalid header value b'Basic <ConsumerKey>'

Are you still experiencing this? Is it the same when you asciinema rec (rec+upload in one go) vs asciinema rec demo.cast + asciinema upload demo.cast?

same issue here, one year later

I have the same issue too

I was able to get around this issue by changing this line to :

encoded_auth = base64.b64encode(bytes(auth, "ascii"))

The solution from @gingermusketeer looks right. HTTP headers are indeed supposed to be ascii encoded. Any chance of this fix making it into a release soon?

I love asciinema and was eagerly looking forward to use this until I was bitten by this bug!

Thanks for digging into this. However it's not about utf-8 vs ascii. Base64 encoding always produces ascii output, regardles of the input.

I figured out it's about the length of the input. Given the password here is the locally generated UUID v4, which is fixed-length, it must be the length of the username, which is taken from $USER env var.

I tested it and in fact username longer than 20 chars causes ValueError: Invalid header value b'Basic ...' error.

Turns out base64.encodebytes return bytes containing the base64-encoded data, with newlines (b'\n') inserted after every 76 bytes of output (see https://docs.python.org/3/library/base64.html#base64.encodebytes). That extra newline inside the header value is the problem.

base64.b64encode doesn't do line breaks, that's why it works. I tested it with utf-8 and it does the job:

encoded_auth = base64.b64encode(bytes(auth, "utf-8"))

I'll release a patch shortly.

Thanks a lot @sickill !