Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Uploading an image using a multipart request with OAuth2 access token #327

@shivrams

Description

@shivrams

I'm having trouble uploading an image using a multipart/form-data request. Traceback is below, I'm using oauthlib 0.6.1

Traceback (most recent call last):
  File "*******oauth_validators.py", line 30, in validate
    server.verify_request(uri, method, body, headers, scopes)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth2/rfc6749/endpoints/base.py", line 61, in wrapper
    return f(endpoint, uri, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/oauth2/rfc6749/endpoints/resource.py", line 62, in verify_request
    request = Request(uri, http_method, body, headers)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/common.py", line 359, in __init__
    self.body = encode(body)
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/common.py", line 354, in <lambda>
    encode = lambda x: to_unicode(x, encoding) if encoding else x
  File "/usr/local/lib/python2.7/dist-packages/oauthlib/common.py", line 288, in to_unicode
    return unicode_type(data, encoding=encoding)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 613: invalid start byte

It seems that as part of request verification, oauthlib expects the body byte string to be encoded in utf-8. Since the image's raw bytes are present in the multipart/form-data body, converting the body to unicode raises the UnicodeDecodeError.

I may be understanding this incorrectly, but is there no way to upload the image as raw bytes instead of base64 encoding the image?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions