[英]Syntax error with python request.post
我正在尝试使用 AWS Lambda 发布 https 请求,以启动我的 databricks 集群。 以下是我的代码,在测试代码“语法错误”时出现错误。 无法找出此处的语法错误:
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"]))
错误响应如下:
Function Logs:
START RequestId: 3829bc0f-a18d-11e8-ae51-ab46ad0bcadb Version: $LATEST
Syntax error in module 'start_cluster': invalid syntax (start_cluster.py, line 26)
请帮我解决问题。 谢谢
new Buffer(token)
不是有效的 Python。 大概你的意思只是Buffer(token)
? (但是你仍然需要从某个地方导入Buffer
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.