python - 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
从某个地方导入)
推荐阅读
- asp.net-web-api2 - 启用 Cors 后 PUT 和 EDIT 出现 404(未找到)
- ssl - 此证书缺少“主机”字段。这使得它不适合网站
- maven-dependency - Maven - ojdbc14.jar 依赖问题
- javascript - Javascript document.ready 在循环中重复(无 DRY)
- java - 以毫秒为单位存储android时间戳值,而不会在字符串变量中丢失其精度
- c++ - 大写的 Boost 日志严重性级别输出
- javascript - 如何使用纯 javascript 动态隐藏表格单元格内容?
- javascript - 如何使用表格中的按钮删除表格中的某些内容
- sql - 查找销售百分比和退货百分比
- c - 声明和定义存储在哪里?