在Heroku中更新bson后,烧瓶应用程序损坏

时间:2018-11-23 06:12:30

标签: python heroku pymongo mongoengine bson

我有一个使用mongoengine并在Heroku上运行的Flask应用,初始化时我使用bson软件包,并将其从0.5.6更新为0.5.7之后 我开始收到以下错误消息:

[2018-11-23 05:56:43 +0000] [39] [INFO] Worker exiting (pid: 39)
[2018-11-23 05:56:43 +0000] [40] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/app/slots_tracker_server/__init__.py", line 5, in <module>
    from mongoengine import connect
  File "/app/.heroku/python/lib/python3.6/site-packages/mongoengine/__init__.py", line 2, in <module>
    from mongoengine import connection
  File "/app/.heroku/python/lib/python3.6/site-packages/mongoengine/connection.py", line 1, in <module>
    from pymongo import MongoClient, ReadPreference, uri_parser
  File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/__init__.py", line 77, in <module>
    from pymongo.collection import ReturnDocument
  File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/collection.py", line 20, in <module>
    from bson.code import Code
  File "/app/.heroku/python/lib/python3.6/site-packages/bson/code.py", line 18, in <module>
    from bson.py3compat import abc, string_type, PY3, text_type
ImportError: cannot import name 'abc'

重新启动服务器时出现此错误,此后我没有在日志中看到错误,但是无法访问该应用程序。 我在Travis-CI中运行相同的配置,但没有任何问题。 关于如何解决它有任何想法吗?

这是我服务器中pip freeze的输出:

blinker==1.4
bson==0.5.7
CacheControl==0.12.5
cachetools==3.0.0
certifi==2018.10.15
chardet==3.0.4
Click==7.0
dateutils==0.6.6
firebase-admin==2.13.0
Flask==1.0.2
Flask-Cors==3.0.7
google-api-core==1.5.2
google-auth==1.6.0
google-cloud-core==0.28.1
google-cloud-firestore==0.30.0
google-cloud-storage==1.13.0
google-resumable-media==0.3.1
googleapis-common-protos==1.5.5
grpcio==1.16.1
gspread==3.0.1
gunicorn==19.9.0
httplib2==0.11.3
idna==2.7
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
mongoengine==0.16.1
msgpack==0.5.6
numpy==1.15.4
oauth2client==4.1.3
pandas==0.23.4
protobuf==3.6.1
pyasn1==0.4.4
pyasn1-modules==0.2.2
pyfcm==1.4.5
pymongo==3.7.2
python-dateutil==2.7.5
python-http-client==3.1.0
pytz==2018.7
raven==6.9.0
requests==2.20.1
requests-toolbelt==0.8.0
rsa==4.0
sendgrid==5.6.0
six==1.11.0
urllib3==1.24.1
Werkzeug==0.14.1

请注意,pymongo>=2.7.1是作为mongoengine的依赖项安装的。

更新: 删除bson并将pymongo==3.7.2添加到要求文件后,出现以下错误:

Traceback (most recent call last):
   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
     worker.init_process()
   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
     self.load_wsgi()
   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
     self.wsgi = self.app.wsgi()
   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
     self.callable = self.load()
   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
     return self.load_wsgiapp()
   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
     return util.import_app(self.app_uri)
   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
     __import__(module)
   File "/app/slots_tracker_server/__init__.py", line 5, in <module>
     from mongoengine import connect
   File "/app/.heroku/python/lib/python3.6/site-packages/mongoengine/__init__.py", line 2, in <module>
     from mongoengine import connection
   File "/app/.heroku/python/lib/python3.6/site-packages/mongoengine/connection.py", line 1, in <module>
     from pymongo import MongoClient, ReadPreference, uri_parser
   File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/__init__.py", line 77, in <module>
     from pymongo.collection import ReturnDocument
   File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/collection.py", line 20, in <module>
     from bson.code import Code
   File "/app/.heroku/python/lib/python3.6/site-packages/bson/code.py", line 18, in <module>
     from bson.py3compat import abc, string_type, PY3, text_type
 ModuleNotFoundError: No module named 'bson.py3compat'

1 个答案:

答案 0 :(得分:1)

pymongo> = 2.7.1指令会覆盖您的bson安装

来自https://github.com/mongodb/mongo-python-driver

  

请勿从pypi安装“ bson”软件包。 PyMongo附带了   自己的bson包;做“ easy_install bson”会安装第三方   与PyMongo不兼容的软件包。

假设您确实要使用第三方bson,则需要

  1. pip uninstall bson(删除通过pymongo软件包降落的覆盖的bson)
  2. pip install bson(重新安装py-bson软件包)

或者您可以修补pymongo安装程序以删除collections.abc行(显然您真的不需要吗?),但是弄​​乱生产打包的代码是有问题的。

pymongo模块 https://github.com/mongodb/mongo-python-driver/blob/master/bson/py3compat.py#L22-L25

您尝试使用的

py-bson模块。 https://github.com/py-bson/bson/blob/master/bson/py3compat.py#L22-L24