我正在尝试从我自己的API获取数据以填充我的web2py数据库。当我从我的操作系统默认python Interpreter(2.7)发出post请求时,这工作正常,但是当我在web2py-enviroment中运行完全相同的代码时,我收到此错误:
AttributeError: addinfourl instance has no attribute '_caller'
Web2Py也运行在相同的python版本上。这是我在web2py项目中的测试代码// models / x_fixtures:
import json
import urllib2
if db(db.rftable.id > 0).count() == 0:
data = {
'ids': [12, 3, 4, 5, 6]
}
url = 'https://eo7sjt6hvj.execute-api.us-west-2.amazonaws.com/prod/tables/getall'
req = urllib2.Request(url, json.dumps(data), {'Content-Type': 'application/json'})
response = urllib2.urlopen(req)
编辑: 整个错误回溯:
Traceback (most recent call last):
File "/home/toni/repos/python/web2py/fsttrpg/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/toni/repos/python/web2py/fsttrpg/applications/fsttrpg/controllers/default.py", line 14, in <module>
AttributeError: addinfourl instance has no attribute '_caller'
我的默认/控制器:
# -*- coding: utf-8 -*-
### required - do no delete
def user(): return dict(form=auth())
def download(): return response.download(request,db)
def call(): return service()
### end requires
def index():
return dict()
def error():
return dict()
答案 0 :(得分:1)
response
是web2py使用的全局变量之一;你的代码只是踩在它上面,这打破了控制器。