当前位置: 首页 > Linux

在SAE中使用qiniuSDKforPython

时间:2023-04-06 02:28:43 Linux

描述SAE(SinaAppEngine)+webpy+qiniusdk实现token生成的业务接口,在部署过程中遇到一系列问题问题1参考qiniuforpython包在创建pythonSAE在web应用过程中,默认提供了webpy,无需安装。但是遇到qiniusdkforpython,就需要安装了。在index.wsgi同级目录下创建一个vendor目录或者其他名字$mkdirvendor然后使用pip命令在vendor目录下安装qiniu$pipinstall-tvendorqiniu修改index.wsgi文件头,添加如下importsaeapp_root=os.path.dirname(__file__)sys.path.insert(0,os.path.join(app_root,'vendor'))同时,上述方法也是加载其他包的方法之一SAEProblem2IOerror上传index.wsgi文件,启动Request,发现还是不行,此时仔细观察SAE中的app登录,会发现如下IO操作错误File"/data1/www/htdocs/421/xetapp/1/vendor/qiniu/zone.py",line22,inZonedef__init__(self,up_host=None,up_host_backup=None,io_host=None,host_cache={},scheme="http",home_dir=tempfile.gettempdir()):文件“/usr/local/sae/python/lib/python2.7/tempfile.py”,第269行,在gettempdirtempdir=_get_default_tempdir()文件“/usr/local/sae/python/lib/python2.7/tempfile.py",line212,in_get_default_tempdir("Nousabletemporarydirectoryfoundin%s"%dirlist))IOError:[Errno2]Nousabletemporarydirectoryfoundin['/tmp','/var/tmp','/usr/tmp','/data1/www/htdocs/421/xetapp/1']yq26注:我发送的请求很清楚POST错误日志提示,zone.py中的__inin文件t__方法的tempfile.gettempdir()请求的是/tmp、/var/tmp等目录,但是SAE中没有这样的目录。将home_dir=tempfile.gettempdir()改为home_dir=sae.core.get_tmp_dir()以使用SAE不要忘记在zone.py文件的头部为tmpdir添加importaes,否则会报错。同理,将qiniu/services/storage/upload_progress_recorder.py中的record_folder=tempfile.gettempdir()改为record_folder=sae.core.get_tmp_dir()不要忘记在upload_progress_recorder.py文件头添加importaes,否则会报错报告