简体   繁体   English

python request.post 的语法错误

[英]Syntax error with python request.post

Am trying post a https request using AWS Lambda, to start my databricks cluster.我正在尝试使用 AWS Lambda 发布 https 请求,以启动我的 databricks 集群。 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. new Buffer(token)不是有效的 Python。 Presumably you meant just Buffer(token) ?大概你的意思只是Buffer(token) (but then you still need to import Buffer from somewhere) (但是你仍然需要从某个地方导入Buffer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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