Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python AWS |模块中的语法错误:无效语法_Python_Python 2.7_Stomp_Amazon Mq - Fatal编程技术网

Python AWS |模块中的语法错误:无效语法

Python AWS |模块中的语法错误:无效语法,python,python-2.7,stomp,amazon-mq,Python,Python 2.7,Stomp,Amazon Mq,我已经创建了python脚本,它作为zip文件上传到AWS Lambda函数中,其中捆绑了stompy库 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 CONNECTI

我已经创建了python脚本,它作为zip文件上传到AWS Lambda函数中,其中捆绑了stompy库

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 ''
我不确定为什么我的消息没有显示在我的输出中,相反,它总是显示响应:null

EDIT:正如@Petesh所指出的,这个问题来自stompyexternal库,它还没有被移植到Python3

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

except socket.timeout, exc:
这是python3的无效语法+

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


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

请将代码以文本形式发布,而不是屏幕截图。我们可能需要将您的代码复制并粘贴到我们自己的文本编辑器中,以重现您的问题,但我们无法从图形中执行此操作。@cdarke我已附上了代码。您可以澄清问题出在stompy模块上,该模块尚未移植到python3上-您的回答不清楚这是问题的触发因素。@AlexK。。非常感谢。如果选择Python2.7,我需要对代码做哪些调整。此外,如何或在何处获得python3+stompylibraries@AlexK.. 此外,我还更新了Python2.7的错误日志。这看起来像是python的另一种选择3@AlexK我已经使用了你的链接并下载了tar.gz文件。但是里面没有stomp.py文件