I'm parsing data from a NMEA data on a tcp socket and I have to store it into a S3. once parsed the data I have to create a json file to be stored into the bucket.
#!/usr/local/bin/python
import boto3
import jsoncode
#initialization
client = boto3.client('s3')
bucketS3='mybucket'
keyS3='myfolder/myfile..json'
serverIP='192.168.10.219'
serverPort=3000
[...]
if fields[0]==b'$GPRMC':
print ('cmd $GPRMC received!', file=sys.stderr)
msg={}
msg['Long']=fields[5]
msg['Lat']=fields[3]
msg['Spd']=fields[7]
msg['Hdg']=fields[8]
msg['Date']=timeStamp
json_object = (json.dumps(msg.decode("utf-8"))
client.put_object(Body=json_object, Bucket=bucketS3, Key=keyS3)
But it retuns the error:
File "/home/myaws/awsS3/myscritpt.py", line 78
client.put_object(Body=json_object, Bucket=bucketS3, Key=keyS3)
^
SyntaxError: invalid syntax
Any idea?
CodePudding user response:
This line:
json_object = (json.dumps(msg.decode("utf-8"))
has 3 open brackets "(" but only 2 close brackets ")".
You should remove the bracket at the front:
json_object = json.dumps(msg.decode("utf-8"))