votes up 1

Data must not be a string.

Package:
Exception Class:
ValueError

Raise code

""" 
        if parameters are supplied as a dict.
        The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype)
        or 4-tuples (filename, fileobj, contentype, custom_headers).
        """
        if (not files):
            raise ValueError("Files must be provided.")
        elif isinstance(data, basestring):
            raise ValueError("Data must not be a string.")

        new_fields = []
        fields = to_key_val_list(data or {})
        files = to_key_val_list(files or {})

        for field, val in fields:
            if isinstance(val, basestring) or not hasattr(val, '__iter__'):
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 0 votes down

Summary:

the data argument for a request must be a dictionary or a list of 2-tuples, it cannot be a string

Reproduce:

import requests
requests.post("http://www.example.com", data="user1") # Error: data is a string

Fix:

import requests
requests.post("http://www.example.com", data={'username':'user1'}) #<--- data must be a dict orlist of 2-tuples  
Jun 02, 2021 cRyp70s answer
cRyp70s 113

Add a possible fix

Please authorize to post fix