# Help with Python code to upload file from Google drive

**URL:** <https://community.hubspot.com/t/help-with-python-code-to-upload-file-from-google-drive/24828>\
**Category:** APIs & Integrations\
**Created:** [August 31, 2020, 9:41pm UTC](https://community.hubspot.com/t/help-with-python-code-to-upload-file-from-google-drive/24828 "2020-08-31T21:41:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ron\_at\_BRCC](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ron_at_brcc/32/59606_2.png) [@Ron\_at\_BRCC](https://community.hubspot.com/u/Ron_at_BRCC)\
**Post date:** [August 31, 2020, 9:41pm UTC](https://community.hubspot.com/t/help-with-python-code-to-upload-file-from-google-drive/24828/1 "2020-08-31T21:41:06Z")

</div>

Hello, I am trying to write a python script to automate a weekly file upload. The file is in my google drive, containing 4 columns, with email address in the 2nd column. I’ve been referencing the document [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/crm/imports)

but getting a 400 error returned. Any help appreciated as I’m not a developer but asked to do this.

--------------------------------------------------------

import requests

import json

url = “[https://api.hubapi.com/crm/v3/imports?hapikey=60\*\*\*](https://api.hubapi.com/crm/v3/imports?hapikey=60***)”

data = {

“name”: “score\_react”,

“files”: [

```
{

  "fileName": "score\_react.csv",

  "fileFormat": "CSV",

  "fileImportPage": {

    "hasHeader": True,

    "columnMappings": \[

      {

                    "ignored": True,

      },

      {

                    "ignored": False,

                    "columnName": "email",

                    "idColumnType": None,

                    "propertyName": "email",

                    "foreignKeyType": None,

                    "columnObjectType": "CONTACT",

                    "associationIdentifiedColumn": False

                },

             {

                    "ignored": False,

                    "columnName": "reactivation\_score",

                    "idColumnType": None,

                    "propertyName": "reactivation\_score",

                    "foreignKeyType": None,

                    "columnObjectType": "CONTACT",

                    "associationIdentifiedColumn": False

                },

                {

                    "ignored": False,

                    "columnName": "reactivation\_category",

                    "idColumnType": None,

                    "propertyName": "reactivation\_category",

                    "foreignKeyType": None,

                    "columnObjectType": "CONTACT",

                    "associationIdentifiedColumn": False

                }

]

```

}

}

]}

datastring = json.dumps(data)

payload = {“importRequest”: datastring}

files = [

(‘files’, open(‘/drive/My Drive/score\_react.csv’,‘r’))

]

response = requests.request(“POST”, url, data = payload, files = files)

print(response.text.encode(‘utf8’))

print(response.status\_code)

---

<div class="post-metadata">

**Author:** ![WendyGoh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wendygoh/32/42320_2.png) [@WendyGoh](https://community.hubspot.com/u/WendyGoh)\
**Post date:** [September 2, 2020, 6:24am UTC](https://community.hubspot.com/t/help-with-python-code-to-upload-file-from-google-drive/24828/2 "2020-09-02T06:24:55Z")

</div>

Hey [@Ron\_at\_BRCC](https://community.hubspot.com/t5/user/viewprofilepage/user-id/143670),

Could you ensure two things here:

1. On the data portion formatting, could you ensure that the order is the same as how the data are listed on the csv file?

2. Additionally, any columns that you’d like to skip the mapping on, could you add this in:

```auto
"ignored": True,
"columnName": "InsertColumnNameToBeSkippedHere"

```

---

<div class="post-metadata">

**Author:** ![Ron\_at\_BRCC](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ron_at_brcc/32/59606_2.png) [@Ron\_at\_BRCC](https://community.hubspot.com/u/Ron_at_BRCC)\
**Post date:** [September 8, 2020, 6:08pm UTC](https://community.hubspot.com/t/help-with-python-code-to-upload-file-from-google-drive/24828/3 "2020-09-08T18:08:24Z")

</div>

Thank you Wendy, it worked !!
