Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
515 views
in Technique[技术] by (71.8m points)

python - Module object not callable error when using Boto3 with DynamoDB

I'm trying to insert an item into my DynamoDB using the Python SDK (I'm not familiar with Python too much). I'm also using MQTT to retrieve some data. Currently the MQTT part works fine (I have some hard coded values for now so I can focus on getting the AWS functionality working)

I'm also using an AWS Educate account so need to pass in my access keys etc (which I've removed from the code for posting here). The code right now is:

from pprint import pprint
import boto3
import paho.mqtt.client as paho
import json
from types import SimpleNamespace

broker = "35.173.177.9"        

#MQTT function
def onMessage(client, userdata, message):
    print("Message recieved: ", str(message.payload.decode("utf-8", "ignore")))

    movie_resp = putItem(1000, "1.1.1.1", "Pi", "06/01/21")

    print("Put item succeeded:")

    pprint(movie_resp, sort_dicts=False)

def putItem(id, ip, deviceName, clickDate, dynamodb=None):
    session = boto3.session(
    aws_access_key_id="",
    aws_secret_access_key="",
    aws_session_token="",
    region_name='us-west-1'
    )

   if not dynamodb:
      dynamodb = session.resource('dynamodb')

   table = dynamodb.Table('piData')

   response = table.put_item(
   Item={
        'ip': ip,
        'id': id,
        'deviceName': deviceName,
        'clickDate': clickDate
    }
   )

   return response

#MQTT code below
client = paho.Client("awsUbuntuEC2")
client.on_message = onMessage
client.connect(broker)
client.subscribe("jsonData")
client.loop_forever()

When running the code I get:

"TypeError: 'module' object is not callable"

on line

session = boto3.session(

Any ideas?

question from:https://stackoverflow.com/questions/65600241/module-object-not-callable-error-when-using-boto3-with-dynamodb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...