SAE(SinaAppEngine) + webpy + qiniu sdk 實現生成token的業務接口 產生一系列問題python
在SAE 中建立python web應用的過程當中默認是支出webpy 的,無需安裝。可是遇到qiniu sdk for python 就須要安裝了。web
在index.wsgi 的同級目錄下建立 vendor目錄或者其餘名字$mkdir vendor
app
而後用pip
命令將qiniu 安裝在vendor目錄下$pip install -t vendor qiniu
python2.7
修改index.wsgi 文件頭添加以下日誌
import sae app_root = os.path.dirname(__file__) sys.path.insert(0, os.path.join(app_root, 'vendor'))
同時以上方法也是SAE中加載其餘包的方式之一code
上傳index.wsgi 文件,發起請求,發現依然不行,此時認真觀察SAE中app 日誌將發現以下IO操做錯誤token
File "/data1/www/htdocs/421/xetapp/1/vendor/qiniu/zone.py", line 22, in Zone def __init__(self, up_host=None, up_host_backup=None, io_host=None, host_cache={}, scheme="http", home_dir=tempfile.gettempdir()): File "/usr/local/sae/python/lib/python2.7/tempfile.py", line 269, in gettempdir tempdir = _get_default_tempdir() File "/usr/local/sae/python/lib/python2.7/tempfile.py", line 212, in _get_default_tempdir ("No usable temporary directory found in %s" % dirlist)) IOError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/data1/www/htdocs/421/xetapp/1'] yq26
注: 我發的請求是POST接口
錯誤日誌提示的很是明白,zone.py 文件中的__inint__ 方法的tempfile.gettempdir() 在請求/tmp 、/var/tmp等,目錄,然而SAE中並無這些目錄ip
將home_dir=tempfile.gettempdir() 改成 home_dir=sae.core.get_tmp_dir() 使用SAE中的tmpdir部署
不要忘記在zone.py 文件頭加入import aes
不然會報錯
同理在qiniu/services/storage/upload_progress_recorder.py
中的record_folder=tempfile.gettempdir()
改成 record_folder=sae.core.get_tmp_dir()
不要忘記在upload_progress_recorder.py 文件頭加入import aes
不然會報錯