我无法使用json.loads转换为dict对象,我无法弄清楚我做错了什么.我得到的确切错误是
ValueError: Expecting property name: line 1 column 2 (char 1)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
from kafka.client import KafkaClient
from kafka.consumer import SimpleConsumer
from kafka.producer import SimpleProducer, KeyedProducer
import pymongo
from pymongo import MongoClient
import json
c = MongoClient("54.210.157.57")
db = c.test_database3
collection = db.tweet_col
kafka = KafkaClient("54.210.157.57:9092")
consumer = SimpleConsumer(kafka,"myconsumer","test")
for tweet in consumer:
print tweet.message.value
jsonTweet=json.loads(({u'favorited': False, u'contributors': None})
collection.insert(jsonTweet)
Run Code Online (Sandbox Code Playgroud)
我很确定错误发生在第2行到最后一行
jsonTweet=json.loads({u'favorited': False, u'contributors': None})
Run Code Online (Sandbox Code Playgroud)
但我不知道该怎么做才能解决它.任何意见,将不胜感激.
我正在尝试设置一个 AWS lambda,它将在我的 EC2 实例中启动 SSM 会话并运行命令。现在为了简单起见,我只是想运行ls。这是我的 lambda 函数:
import json
import boto3
def lambda_handler(commands, context):
"""Runs commands on remote linux instances
:param client: a boto/boto3 ssm client
:param commands: string, each one a command to execute on the instance
:return: the response from the send_command function (check the boto3 docs for ssm client.send_command() )
"""
client = boto3.client('ssm')
print ("Hello world")
resp = client.send_command(
DocumentName="AWS-RunShellScript",
# Would normally pass commands param here but hardcoding it instead for …Run Code Online (Sandbox Code Playgroud) 我已经为此工作了很长时间,任何帮助将不胜感激。
我在这里想做的是 ssh 到测试服务器,然后 cd ..,然后通过 python 打印该文件夹中的目录列表。这段代码是我最好的尝试:
def subprocess_cmd(command):
process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
print "Test 1"
proc_stdout = process.communicate()[0].strip()
#proc_stdout= process.stdout.readlines() (Gives same outcome as communicate)
#proc_stdout= process.stdout.read() (Gives same outcome as communicate)
print "Test 2"
print proc_stdout
Run Code Online (Sandbox Code Playgroud)
subprocess_cmd('ssh user@server -p 111;cd ..;ls')
由于某种原因,这个函数总是挂在“proc_stdout =”步骤。它从不打印“Test 2”或返回文件列表。不过,如果我取出 ssh 命令,它就可以正常工作。我期望在终端中看到类似这样的内容,但终端挂起,我无法再与其交互:
dredbounds-computer: python file_name.py
Test 1
Test 2
FileA
FileB
FileC
Run Code Online (Sandbox Code Playgroud)
更新:我修改了代码并放置了 proc_stdout= process.stderr。交流()。这是我更新的代码:
def subprocess_cmd(command):
process = subprocess.Popen(command,stdout=subprocess.PIPE, shell=True)
print "Test 1"
proc_stderr= process.stderr. communicate()
print "Test 2"
print proc_stderr
print …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 python 脚本中运行一些 boto 函数。我需要创建一个具有执行这些 boto 函数所需的最低权限的 IAM 策略。有没有一种好方法可以将这些 boto 函数与执行它们所需的 AWS IAM 权限相关联。
例如,这是我拥有的 boto 模块(python)。用户需要什么 IAM 权限才能运行它们?有没有好的方法可以找到这个?
boto.ec2.autoscale.connect_to_region
boto.ec2.elb.connect_to_region
boto.ec2.connect_to_region
boto.ec2.instance.Instance
boto.ec2.elb.loadbalancer.LoadBalancer
boto.ec2.autoscale.group.AutoScalingGroup
Run Code Online (Sandbox Code Playgroud) python ×4
boto3 ×2
amazon-iam ×1
aws-lambda ×1
aws-ssm ×1
bash ×1
boto ×1
json ×1
pymongo ×1
ssh ×1
subprocess ×1