顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2020年6月20日 星期六

[Flask] SQLALCHEMY_TRACK_MODIFICATIONS error 處理

在導入postgresql至heroku的同時,使用Flask遭遇以下error:

builtins
.KeyError KeyError: 'SQLALCHEMY_TRACK_MODIFICATIONS'

2020年6月13日 星期六

[heroku][postgresql] 使用CLI介面清空資料庫table所有資料內容

建立好heroku postgresql之後,
有時候需要直接清空資料庫,但又不想重新建立shema
或者重新migration

這時候就可以透過CLI直接清除資料庫


[note] psycopg2 無法安裝排解

在安裝套件時
sudo pip install psycopg2

安裝遭遇以下log:

    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-dBC6Co/psycopg2/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-dBC6Co/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /private/tmp/pip-install-dBC6Co/psycopg2/
    Complete output (27 lines):
    /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'project_urls'
      warnings.warn(msg)
    /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
      warnings.warn(msg)
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

    Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.

    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).

    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

請直接安裝
sudo pip install psycopg2-binary即可解決





2019年11月12日 星期二

[note] 在heroku平台找不到pytz套件的解決方式

在撰寫slack app時,
使用timezone套件,
----------------
import pytz
----------------
發佈至heroku時,遭遇以下log:
----------------
2019-11-12T16:34:01.371570+00:00 app[web.1]: import pytz
2019-11-12T16:34:01.371634+00:00 app[web.1]: ModuleNotFoundError: No module named 'pytz'
----------------

2019年11月11日 星期一

[note] 解決line bot 重複發送訊息兩次問題

在串接linebot with python

使用slack會發現主動傳訊息會發送兩次的狀況發生。

影響的api有

line_bot_api.push_message()

line_bot_api.broadcast()

只要是主動傳訊息的都會發生傳送兩次

那該如何解決呢?


2019年10月8日 星期二

[Note] ImportError: No module named pandas 排除

發現以下error時,代表有使用到pandas模組但是系統找不到此模組。

這裡紀錄在MAC OSX上安裝pandas模組的方法


[note] SyntaxError: Non-ASCII character '\xe8' in file 排除

在寫一些python測試code時,遭遇以下error

SyntaxError: Non-ASCII character '\xe8' in file

這裡記錄一下解決方法


2019年10月5日 星期六

[note] 如何在HTML網頁檔案之中嵌入github 原始碼

這裡是示範如何在blogger or 一般網頁之中嵌入github source code

[Trouble shooting] AttributeError: 'module' object has no attribute 'time' 解決方式

今天嘗試寫一個python遭遇以下:


 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 95, in <module>
    _startTime = time.time()
AttributeError: 'module' object has no attribute 'time'

明明沒有用到time 模組,為什麼還會出現此訊息呢?


2019年10月2日 星期三

2019年9月30日 星期一

[note] Heroku R10 錯誤解決

在heroku部署計畫之中,

會遇到R10的錯誤

原因出自於:heroku無法指令port
會產生等待過久的timeout發生

因此,需要透過指令系統port來指派(由heroku平台端指派)

假設是node.js可以透過以下

.listen(process.env.PORT || 5000)
如果是python (flask)可以透過以下:
ort = int(os.environ.get("PORT", 5000))
app.run(debug=True, host='0.0.0.0', port=port)

參考:
1. Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
2. Heroku App crashes immediately with R10 and H10 errors