简体   繁体   中英

Syntax error with python request.post

Am trying post a https request using AWS Lambda, to start my databricks cluster. Following is my code, and am getting error while testing the code "Syntax error". Unable to figure out the syntax error here:

from __future__ import print_function
import json
import boto3
import time
import urllib
import re
import pymysql
import sys
import requests

s3 = boto3.client('s3')
domain = 'mydatabricks.cloud.databricks.com'
token = 'my-token-id'

data = JSON.stringify({"cluster_id": "myclusterid"});

def lambda_handler(event, context):
    source_bucket = event['Records'][0]['s3']['bucket']['name']
    source_key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']) 

    # Just print function  
    print("Source bucket : ", source_bucket)
    print("Source Key : ", source_key)

    response = requests.post('https://%s/api/2.0/clusters/start' % (domain),
    headers = {"Authorization": "Basic " + new Buffer(token).toString("base64")},
    json = {"cluster_id": "myclusterid"}
)

    if response.status_code == 200:
      print(response.json()['cluster_id'])
    else:
      print("Error launching cluster: %s: %s" % (response.json()["error_code"], response.json()["message"]))

The error response is as follows:

Function Logs:
START RequestId: 3829bc0f-a18d-11e8-ae51-ab46ad0bcadb Version: $LATEST
Syntax error in module 'start_cluster': invalid syntax (start_cluster.py, line 26)

Please help me resolve the issue. Thx

new Buffer(token) is not valid Python. Presumably you meant just Buffer(token) ? (but then you still need to import Buffer from somewhere)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM