0

在 Python 3.7 中,

from facebookads.adobjects.adlabel import AdLabel 

结果是

Traceback (most recent call last):
  File "/Users/mohan/growth-tools/facebook-experiment/main.py", line 4, in <module>
    from facebookads.adobjects.adlabel import AdLabel
  File "/Users/mohan/growth-tools/facebook-experiment/venv/lib/python3.7/site-packages/facebookads/adobjects/adlabel.py", line 22, in <module>
    from facebookads.adobjects.abstractcrudobject import AbstractCrudObject
  File "/Users/mohan/growth-tools/facebook-experiment/venv/lib/python3.7/site-packages/facebookads/adobjects/abstractcrudobject.py", line 564
    params=None, async=False, include_summary=True,
                     ^
SyntaxError: invalid syntax

我认为问题在于,从 Python 3.7 开始,异步已成为保留关键字。是否有任何解决方法可以让我继续使用此 SDK?

4

5 回答 5

2

显然,这个模块不支持 3.7。因此,您一如既往地在供应商不提供支持的情况下进行:编辑和/或分叉它。

例如,在 Visual Studio 2017 中构建 TclTk 时,在模块的代码库中替换async->错误:async_

$ find /Users/mohan/growth-tools/facebook-experiment/venv/lib/python3.7/site-packages/facebookads \
! -type d -a -name '*.py' -print0 |\
xargs -0 python -c '
import sys,re
for fname in sys.argv[1:]:
 with open(fname,"rb") as f: l=f.read()
 (r,n)=re.subn(r"\b(async)\b",r"\1_",l)
 if n>0:
  with open(fname,"wb") as f: f.write(r)
'
于 2018-12-13T15:31:14.080 回答
0

我最终只是遍历了所有文件并用“async_”替换了“async”的任何实例,我的解决方案如下:

import os, re
path = r"path\to\facebookads"

python_files = []

for dirpath, dirnames, filenames in os.walk(path):
    for filename in filenames:
        if filename.endswith(".py"):
            python_files.append(os.path.join(dirpath, filename))

for python_file in python_files:

    with open(python_file, "r") as f:
        text = f.read()
        revised_text = re.sub("async", "async_", text)

    with open(python_file, "w") as f:
        f.write(revised_text)
于 2019-04-04T17:04:15.163 回答
0

如果您认为 SDK 确实存在问题,您就不能在sudo cd那里然后编辑它吗?

如果可以,那么最简单的选择就是遍历每个实例async并检查它是否是变量 async,如果是则替换它。

于 2018-12-13T15:26:51.157 回答
0

尝试facebook_business代替facebookads. 另请参阅此相关答案

于 2020-07-27T12:56:46.457 回答
0

Facebook已为 python 库修复了此问题,请改为使用此处is_asyc所示。

于 2020-05-13T22:48:58.180 回答