I have a python script that connects to my database and updates it with a file that i specify. But i keep getting a syntax error on line 5 and for the life of me i can not figure out what it is. If someone could pointit out and how to fix it i would b so greatfull.

import request

url = self._resolve_url('http://website.com/mail/subscriber_upload/index')
files = {'file': ('filename', open(home/hatterx/Desktop/Bronto_Files, 'rb'))}
data = {'source': FACTS Daily Import, 'site_id': xxxxx, 'user_id': xxxxx, 'key': xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 'format': csv, 'action': add, 'listname': TEST List For API Inegration}
headers = {'content-type': 'multipart/form-data'}
res = requests.post(url, files=files, data=data, headers=headers)
return res.json

Can you post the full traceback, please? It is hard to determine what ther error is without seeing the error messages.

On a guess, though, it is that you need to put the name of the source file and the list in quotations.

data = {'source': 'FACTS Daily Import', 'site_id': xxxxx, 'user_id': xxxxx, 'key': xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 'format': csv, 'action': add, 'listname': 'TEST List For API Inegration'}

This is what my terminal produces when i try and run my code.

File "/home/hatterx/Desktop/test3.py", line 5

data = {'source': 'FACTS Daily Import', 'site_id':xxxxx 'user_id': xxxxx, 'key': xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 'format': csv, 'action': add, 'listname': 'TEST List For API Inegration'}


                                                                ^

SyntaxError: invalid syntax

You dropped a comma between the values for 'site_id' and 'user_id'. Easy mistake to make, hard to find once it has been made - I've done it myself a number of times and spent a lot of time trying to make sense of the error messages.

i cought that myself after rereading my code still giving me the error and pointing to action: add and the listname items for some reason.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.