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

Skip to content

test_fieldstorage_not_multipart fails #446

@mtelka

Description

@mtelka

The test_fieldstorage_not_multipart fails with the following error:

_______ Test_cgi_FieldStorage_Py3_tests.test_fieldstorage_not_multipart ________

self = <test_compat.Test_cgi_FieldStorage_Py3_tests object at 0x7fffa6945950>

    def test_fieldstorage_not_multipart(self):
        from webob.compat import cgi_FieldStorage

        POSTDATA = b'{"name": "Bert"}'

        env = {
            'REQUEST_METHOD': 'POST',
            'CONTENT_TYPE': 'text/plain',
            'CONTENT_LENGTH': str(len(POSTDATA))
        }
        fp = BytesIO(POSTDATA)
>       fs = cgi_FieldStorage(fp, environ=env)

tests/test_compat.py:67:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.7/cgi.py:499: in __init__
    self.read_single()
/usr/lib/python3.7/cgi.py:692: in read_single
    self.read_binary()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = FieldStorage(None, None)

    def read_binary(self):
        """Internal: read binary data."""
        self.file = self.make_file()
        todo = self.length
        if todo >= 0:
            while todo > 0:
                data = self.fp.read(min(todo, self.bufsize)) # bytes
                if not isinstance(data, bytes):
                    raise ValueError("%s should return bytes, got %s"
                                     % (self.fp, type(data).__name__))
                self.bytes_read += len(data)
                if not data:
                    self.done = -1
                    break
                if self._binary_file:
                    self.file.write(data)
                else:
>                   self.file.write(data.decode())
E                   TypeError: a bytes-like object is required, not 'str'

/usr/lib/python3.7/cgi.py:717: TypeError

Tested with WebOb-1.8.7. The test fails with both Python 3.7.16 and Python 3.9.16.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions