DynamoDB查询的Python代码适用于v3.6,但不适用于python 2.7

编程入门 行业动态 更新时间:2024-10-28 20:16:32
本文介绍了DynamoDB查询的Python代码适用于v3.6,但不适用于python 2.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有boto3框架的DynamoDB查询,该查询可在运行Python 3.6的本地计算机上运行,​​但不能在运行Python 2.7的服务器上运行。

I have a DynamoDB query with boto3 framework, which works on my local machine running Python 3.6, but not my server running Python 2.7.

我的工作代码本地计算机:

The working code on my local machine:

dyndb = boto3.resource('dynamodb') table = dyndb.Table('XXXXXXX') response = table.query( IndexName = "XXX-XXX-index", ProjectionExpression = "AssessID,SNo,Details,Status,OTP", KeyConditionExpression = Key('OTP').eq(otp))

在服务器上运行的代码。 ..

The code running on server...

global user_otp dyndb = boto3.resource('dynamodb') table = dyndb.Table('XXXXXX') otp = int(user_otp) print("converting string otp to int otp") # it is printed on console response = table.query( IndexName = "XXX-XXX-index", ProjectionExpression = "AssessID,SNo,Details,Status,OTP", KeyConditionExpression = Key('OTP').eq(otp) & Key('SNo').between(1,5)) print ("response code is executing file") # it is not printed on console

当我打印输出时,显示第一张打印,但不显示表格查询后的第二张打印。

When I print the output, the first print is shown but not the second print after the table query.

我正在使用 OTP 作为分区键并且 SNo 作为排序键。即使在使用分区键和排序键的情况下,我也只能在本地计算机上使用分区键获得结果,而在服务器上却没有。

I am making this query on global index with OTP as partition key and SNo as sort key. I get results on my local machine with only the partition key, but not on my server, even using both the partition and sort key.

DynamoDB不会引发任何异常。相反,我得到龙卷风websocket异常。

DynamoDB does not raise any exceptions. instead I am getting tornado websocket exception.

control coming to process and response function user otp mentioned is 3086and its type <type 'int'> converting string otp to int otp ERROR:tornado.application:Exception in callback <functools.partial object at 0x7f33b6ce7890> Traceback (most recent call last): File "/usr/lib64/python2.7/site-packages/tornado/ioloop.py", line 758, in _run_callback ret = callback() File "/usr/lib64/python2.7/site-packages/tornado/stack_context.py", line 300, in null_wrapper return fn(*args, **kwargs) File "/usr/lib64/python2.7/site-packages/tornado/ioloop.py", line 779, in _discard_future_result future.result() File "/usr/lib64/python2.7/site-packages/tornado/concurrent.py", line 261, in result raise_exc_info(self._exc_info) File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 1141, in run yielded = self.gen.throw(*exc_info) File "/usr/lib64/python2.7/site-packages/tornado/websocket.py", line 888, in _receive_frame_loop yield self._receive_frame() File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 1133, in run value = future.result() File "/usr/lib64/python2.7/site-packages/tornado/concurrent.py", line 261, in result raise_exc_info(self._exc_info) File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 1147, in run yielded = self.gen.send(value) File "/usr/lib64/python2.7/site-packages/tornado/websocket.py", line 975, in _receive_frame handled_future = self._handle_message(opcode, data) File "/usr/lib64/python2.7/site-packages/tornado/websocket.py", line 1000, in _handle_message return self._run_callback(self.handler.on_message, decoded) File "/usr/lib64/python2.7/site-packages/tornado/websocket.py", line 548, in _run_callback self.handler.log_exception(*sys.exc_info()) AttributeError: 'WebSocketClientConnection' object has no attribute 'log_exception'

推荐答案

我认为无属性log_exception是Tornado 5中的一个错误,该错误已在Tornado 6中修复。但是,Tornado 6仅支持Python 3,因此在Python 2中,您可以获得较早的版本。

I think "no attribute log_exception" was a bug in Tornado 5 that was fixed in Tornado 6. However, Tornado 6 only supports Python 3, so in Python 2 you get the older version.

这里还有另一个错误,但是您看不到它是什么,因为Python 2的错误处理不如Python 3更好。而且该错误显然不会在Python 3上发生。如果您必须继续支持Python 2,请尝试在<$ c $的主体周围添加 try / except 块。 c> on_message 回调(或使用 read_message 接口代替 on_message 回调)。

There's also another error here, but you can't see what it is because Python 2's error handling is not as good as Python 3's. And the error apparently doesn't occur on Python 3. If you must continue to support Python 2, try adding a try/except block around the body of your on_message callback (or use the read_message interface instead of the on_message callback).

更多推荐

DynamoDB查询的Python代码适用于v3.6,但不适用于python 2.7

本文发布于:2023-07-04 06:40:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1019770.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   但不   代码   Python   DynamoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!