- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对创建的自定义 apache Airflow Hook 运行一些测试。测试通过了,但出现了这个奇怪的错误(不影响测试),如下所示。这很奇怪,因为 BrazeHook 可以导入并使用,并且不会在任何其他类或测试中导致错误
[2019-06-21 16:11:27,748] {{settings.py:182}} INFO - settings.configure_orm(): Using pool settings. pool_size=5, pool_recycle=1800, pid=53175
[2019-06-21 16:11:29,243] {{plugins_manager.py:143}} ERROR - cannot import name 'BrazeHook'
Traceback (most recent call last):
File "/xxxxx/xxx/venv/lib/python3.6/site-packages/airflow/plugins_manager.py", line 137, in <module>
m = imp.load_source(namespace, filepath)
File "/xxxxx/bloodflow/venv/lib/python3.6/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/xxxx/xxx/plugins/operators/s3_to_braze_operator.py", line 9, in <module>
from plugins.hooks.braze_hook import BrazeHook
ImportError: cannot import name 'BrazeHook'
[2019-06-21 16:11:29,246] {{plugins_manager.py:144}} ERROR - Failed to import plugin /xxxx/xxx/plugins/operators/x_to_braze_operator.py
Ran 1 test in 0.071s
OK
import requests
from braze.client import BrazeClient, BrazeClientError, BrazeInternalServerError
class BrazeImportError(Exception):
def __init__(self, message):
"""
Error occured while trying to import the users data into Braze
:param str message: error message returned by Braze or message out ot anu other exception.
"""
self.message = message
super(BrazeImportError, self).__init__()
class BrazeHook(BaseHook):
def __init__(self, braze_conn_id='braze', *args, **kwargs):
self.connection = self.get_connection(braze_conn_id)
def track(self, attributes=None, events=None, purchases=None):
"""
adds/modifies user data through /users/track endpoint of braze
:param attributes: dict or list of user attributes dict (external_id, ... }
:return:
:throws BrazeClientError encapsulation various errors returned by Braze
"""
try:
client = BrazeClient(api_url=self.connection.host, api_key=self.connection.extra_dejson.get('api_key'))
return client.user_track(attributes=attributes, events=events, purchases=purchases)
except requests.exceptions.ConnectionError as ce:
raise BrazeImportError(ce.args[0])
except (BrazeClientError, BrazeInternalServerError) as be:
raise BrazeImportError(message=str(be))
class TestBrazeHook(unittest.TestCase):
@responses.activate
def test_request_path(self):
responses.add(responses.POST, "https://brazeurl/users/track",
json={'errors': u'', u'message': u'success', 'status_code': 200, 'success': True}, status=201)
handler = BrazeHook(braze_conn_id="braze")
response = handler.track(attributes=[])
self.assertEqual(201, response['status_code'])
更新按照评论中的要求添加错误消息引用的运算符
class S3ToBrazeOperator(BaseOperator):
"""
Copies Reader Score based audiences from S3 to Braze
"""
template_fields = ()
template_ext = ()
ui_color = '#ededed'
@apply_defaults
def __init__(self,
s3_bucket,
s3_path,
s3_conn_id,
braze_conn_id,
columns,
*args, **kwargs):
super(S3ToBrazeOperator, self).__init__(*args, **kwargs)
self.s3_bucket = s3_bucket
self.s3_path = s3_path
self.s3_conn_id = s3_conn_id
self.braze_conn_id = braze_conn_id
self.columns = columns
def execute(self, context):
request_handler = BrazeHook(braze_conn_id=self.braze_conn_id)
....
scores = dd.read_csv(f"s3://{self.s3_bucket}/{self.s3_path}/*",
sep=";", compression="gzip", header=None, storage_options=options).compute()
scores.columns = self.columns
attributes = []
# batches the results according to step size
for batch in chunk(scores, BRAZE_API_STEP):
batch.apply(lambda user: {
"external_id": user.user_id,
....
}, axis=1).apply(lambda attribute: attributes.append(attribute))
try:
request_handler.track(attributes=attributes)
except Exception as e:
logging.error("Error {}".format(str(e)))
raise
最佳答案
您可以尝试的一件事是将 __init__.py
文件放入插件目录中,其中包含以下内容:
from airflow.plugins_manager import AirflowPlugin
from plugins.hooks.braze_hook import BrazeHook
from plugins.operators.x_to_braze_operator import S3ToBrazeOperator
class BrazePlugin(AirflowPlugin):
name = "braze_plugin"
operators = [S3ToBrazeOperator]
sensors = []
hooks = [BrazeHook]
executors = []
macros = []
admin_views = []
flask_blueprints = []
menu_links = []
appbuilder_views = []
appbuilder_menu_items = []
这可能会有所帮助,但我并不是 100%。
关于python - plugins_manager.py 错误 - 无法导入插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56705429/
我使用的是 Windows 8.1 和 Python 2.7,我在特定文件路径中设置了所有文件(希望正确),但每当我运行 python manage.py runserver 时,我都会收到此错误。
背景: 我有一个像这样的目录结构: Package/ setup.py src/ __init__.py __main__.py cod
我从这个线程运行了一个示例代码。 How to properly use coverage.py in Python? 但是,当我执行此命令时 py.test test.py --cov=sample
IPython 0.13.1 文档说: $ ipython -h ... Usage ipython [subcommand] [options] [files] If invoked
我写了一个网站,让我困惑的是当我运行这个网站时,首先我需要启动应用程序,所以有 3 种方法: sudo python xxx.py python xxx.py xxx.py 每一个我都不清楚怎么用,目
我不确定为什么它不起作用,这可能是一个您无法解决的问题,但我只是想知道为什么它不起作用。如果我浪费了您的时间,或者没有正确地提出问题,我很抱歉,我 16 岁,对 Python 还算陌生。 在main.
鉴于以下情况:models.py from .managers import PersonManager from django.db import models class Person(model
有没有办法将参数传递给 web.py 处理程序类构造函数? 例如。这些参数可能来自命令行(当主 web.py 脚本运行时),在第一个参数(作为端口号)之后 最佳答案 当然,这取决于你的意思。毕竟都是p
我对 python/django 编程很陌生,因为我没有编程背景。我正在在线上课,我只想确切地知道 manage.py 文件的作用。我试过用谷歌搜索它,但除了在 django-admin.py 周围放
我想将类别及其子类别保存到数据库中,这里每个类别都有多个子类别。您能帮我保存与类别相对应的用户、类别和多个子类别吗?Models.py、Serializers.py、Views .py 并附加传入请求
所以我的机器人开始有很多命令,并且在 main.py 上变得有点困惑。我知道有一种方法可以将命令存储在其他文件中,然后在 discord.js 上触发它们时将它们应用于 main.py。在 disco
我正在尝试制作一个类似于 mee6 的 Discord 机器人,因为它会按特定时间间隔计算用户在我的 Discord 服务器中发送的消息。我已经在网上搜索过,但即使有类似的问题也找不到我要找的东西。例
我正在尝试制作一个机器人,它根据特定 channel 中的消息创建线程。如果有在 discord.py 中的文本 channel 中创建线程的方法,请告诉我。 最佳答案 是的,但有一个问题。 当前版本
我一直在尝试制作一个命令来显示一些信息,然后当我对表情使用react时,它应该会显示另一组信息。 我尝试使用 this 的部分内容,特别是第 335 到 393 行的部分让它工作。但是,它什么也不做。
这是我试过的代码: @client.event async def on_message(message): if client.user.mention in message.content
我试过这段代码,机器人说猜但没有回应我的猜测。 @commands.command() async def game(self, ctx): number = random.randint(0
我决定尝试让我的不和谐机器人播放音乐,但我已经卡住了。主要是因为我找不到任何资源来帮助当前版本,我一直在从文档中获取所有内容。但是,我不知道如何检查机器人是否已连接到语音 channel 。 我试过
我在一个目录中有三个文件: # Untitled-1.py print("UTITLEDPY") if __name__== "__main__": from telegram.ext imp
我对 python 相当陌生,并且一直只使用 Jupyter Notebooks。当我需要运行我已保存在计算机中某处的 .py 文件时,我通常所做的就是使用魔术命令 %run %run '/home/
我有 Django 1.4 和 Python 2.6.6当我使用“django-amdin.py startproject djproject”时,请按照网页中的步骤操作 https://www.ib
我是一名优秀的程序员,十分优秀!