AWS |模块中的语法错误:语法无效 [英] AWS | Syntax error in module': invalid syntax

查看:315
本文介绍了AWS |模块中的语法错误:语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了python脚本,该脚本以zip文件的形式上传到AWS Lambda函数中,其中捆绑了Stompy库.

I have created python script which is uploaded as a zip file in AWS Lambda function with stompy libraries bundled in them.

python 2.7的日志:-

Logs for python 2.7:-

Response:
null

Request ID:
"c334839f-ee46-11e8-8970-612f1dc92e41"

Function Logs:
START RequestId: c334839f-ee46-11e8-8970-612f1dc92e41 Version: $LATEST
CONNECTION Started
CONNECTION established
CONNECTION Subscribed
[WARNING]   2018-11-22T11:07:12.798Z    c334839f-ee46-11e8-8970-612f1dc92e41    Unknown response frame type: '' (frame length was 3)
END RequestId: c334839f-ee46-11e8-8970-612f1dc92e41
REPORT RequestId: c334839f-ee46-11e8-8970-612f1dc92e41  Duration: 10027.75 ms   Billed Duration: 10100 ms   Memory Size: 128 MB Max Memory Used: 30 MB

我的代码:-

import time
import boto3
import stomp

kinesis_client = boto3.client('kinesis')


class Listener(stomp.ConnectionListener):
    msg_list = []
    def on_error(self, headers, message):
        print('received an error "%s"' % message)

    def on_message(self, headers, message):
        print('received a message "%s"' % message)
        kinesis_client.put_record(
            StreamName='Purchasing',
            Data=u'{}\r\n'.format(message).encode('utf-8'),
            PartitionKey='0'
        )


def lambda_handler(event, context):
    conn = stomp.Connection(host_and_ports=[('b-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 8162)])
    lst = Listener()
    conn.set_listener('Listener', Listener())
    conn.start()
    conn.connect(login='test_mq', passcode='test_mq')
    conn.subscribe(destination='/queue/Purchasing', id='b-4714-4441-8166-47aae158281a', ack='auto')
    message = lst.msg_list
    print('Waiting for messages "%s"' % message)
    time.sleep(10)
    conn.disconnect()
    return ''

我不确定为什么我的消息没有显示在输出中,而是总是显示"Response:null".

I am not sure why my message is not showing up in my output,instead it always shows up "Response: null".

推荐答案

EDIT :如@Petesh所指出的,该问题来自stompy(外部库),尚未移植到Python3.

EDIT: As pointed by @Petesh, the issue comes from stompy(external library), which hasn't been ported to Python3.

如果您查看源代码,则可以找到以下内容:

If you check the source code, you can find this:

except socket.timeout, exc:

这是python3 +的无效语法

which is invalid syntax for python3+

如果您在python3.6/3.7环境中运行Lambda,则语法无效.

If you run your Lambdas in python3.6/3.7 environment, the syntax is invalid.

如果选择python 2.7,问题可能会消失,但是您还必须调整代码,库等.

The issue might go away if you choose python 2.7, but you will also have to adjust your code, libraries, etc.

这篇关于AWS |模块中的语法错误:语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆