• Hi all,

    I'm trying to use the recently introduced WriteAPI to create topics and concurrently upload a file.
    I'm doing it via Python and I've already succeeded in create a simple topic without a file using something lilke

            payload = {
                "cid": cid,
                "title": title,
                "content": message
            }
    
            headers = {
                'Authorization': 'Bearer '+nodebbToken,
                'Content-Type': 'application/json'
            }
    
            response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
    

    but when it's about files using

            payload = {
                "cid": backstage_cid,
                "title": backstage_title,
                "content": backstage_message
            }        
            headers = {
            'Authorization': 'Bearer '+nodebbToken,
            'Content-Type': 'multipart/form-data'
            }        
            verifySSL = False
    
            print (payload)
    
            if (useFile):
                with open(backstage_file, 'rb') as f:
                    response = requests.request("POST", url, headers=headers, data=payload, verify=verifySSL, files={backstage_file: f})
    

    it returns
    Error: Required parameters were missing from this API call: cid, title, content cause passing the parameters in a plain dictionary rather than a JSON object seems not doable.

    The switch from JSON to dictionary is needed otherwise I wouldn't have been able to pass a file together with such header

            headers = {
            'Authorization': 'Bearer '+nodebbToken,
            'Content-Type': 'multipart/form-data'
            }    
    

    Has anybody valuable suggestions here?

    Thanks in advance, Riccardo

Suggested Topics

| |