What am I doing wrong in this QBO v3 API (IPP) Attachments upload python request?
Question: Intuit offers [these
instructions](https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/020_key_concepts/attachments#Request_Body)
for uploading attachments (which become [Attachable
objects](https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/attachable)
that can be associated with one or more transactions).

I **believe** I'm using python's requests module (via [rauth's OAuth1Session
module](http://rauth.readthedocs.org/en/latest/api/#oauth-1-0-sessions)—see
below for how I'm creating the session object) to generate these requests.
Here's the code leading up to the request:

    
    
    print request_type
    print url
    print headers
    print request_body
    
    r = session.request(request_type, url, header_auth,
                        self.company_id, headers = headers,
                        data = request_body, **req_kwargs)
    
    result = r.json()
    
    print json.dumps(result, indent=4)
    

and the output of these things:

    
    
    POST
    https://quickbooks.api.intuit.com/v3/company/0123456789/upload
    {'Accept': 'application/json'}
    Content-Disposition: form-data; name="Invoice 003"; filename="Invoice 003.pdf"
    Content-Type: application/pdf
    <@INCLUDE */MyDir/Invoice 003.pdf*@>
    {
     "Fault": {
      "type": "SystemFault", 
      "Error": [
       {
        "Message": "An application error has occurred while processing your request", 
        "code": "10000", 
        "Detail": "System Failure Error: Cannot consume content type"
       }
      ]
     }, 
     "time": "[timestamp]"
    }
    

I have confirmed (by uploading an attachment through the QBO web UI and then
querying the Attachable object through the API) that application/pdf is
included in the list of acceptable file types.

At sigmavirus24's suggestion, I tried removing the Content-Type line from the
headers, but I got the same result.

Here's how I'm creating the session object (which, again, is working fine for
other QBO v3 API requests of every type you see in Intuit's API Explorer):

    
    
    from rauth import OAuth1Session
    
    def create_session(self):
        if self.consumer_secret and self.consumer_key and self.access_token_secret and self.access_token:
            session = OAuth1Session(self.consumer_key,
                self.consumer_secret,
                self.access_token,
                self.access_token_secret,
                )
            self.session = session
        else:
            raise Exception("Need four creds for Quickbooks.create_session.")
        return self.session
    

What might I be missing here?

EDIT: current area of exploration is
[here](https://github.com/litl/rauth/issues/109); I just formed the header you
see (that has the "INCLUDE" string there) directly. Perhaps I should be using
rauth to attach the file...


Answer: Without being able to see what code you're using with requests, I'm going to
take a shot in the dark and tell you to remove setting your own `Content-
Type`. You probably don't want that. It looks like you want `multipart/form-
data` and requests will set that on its own if you stop fighting it.

* * *

It looks like you're missing the boundaries that QuickBooks is expecting
(based on what you linked).

    
    
    ---------------------------acebdf13572468
    Content-Disposition: form-data; name="file_content_01"; filename="IMG_0771.jpg"
    Content-Type: image/jpeg
    <@INCLUDE *Y:\Documents\IMG_0771.jpg*@>
    ---------------------------acebdf13572468--
    

The first and last line above seem to be what you're missing.

