可以发布到web2py的数据是否有限制?

时间:2019-09-20 21:39:13

标签: python post web2py

我正在将数据发布到web2py API。对于较短的数据字符串,POST成功执行而不会出现问题。稍长的数据字符串将返回“ Response [200]”,但该条目确实已成功发布到数据库。

这是用于www.pythonanywhere.com上的web2py部署。对于Web2Py,Python或www.pythonanywhere.com(运行web2py的地方)似乎没有任何有意义的限制,尤其是对于我正在使用的数据大小长度(确实很小)。

这里是一个例子。 data_list中的“ json_data”已成功发布。 data_list中的“ json_data2”没有。 'json_data'仅约200个字符长。 “ json_data2”大约为1000。长度是我可以找到的唯一确定成功失败的变量,但是我很难相信长度是问题所在:

import requests
from requests.auth import HTTPBasicAuth
from datetime import datetime

auth=HTTPBasicAuth('LoginID', 'Password')
json_data = '{"batt chrg": {"dat": "-999%", "measurement": "percent", "unit": "electric", "entrytype": "subunitStatus"}, "pv gen": {"dat": "-999 W", "measurement": "level", "unit": "electric", "entrytype": "subunitStatus"}}'
json_data2 = '{"download": {"entrytype": "subunitStatus", "dat": "9 Mbit/s", "measurement": "level", "unit": "comms"}, "batt chrg": {"entrytype": "subunitStatus", "dat": "94.4%", "measurement": "percent", "unit": "electric"}, "pv gen": {"entrytype": "subunitStatus", "dat": "543 W", "measurement": "level", "unit": "electric"}, "living space": {"entrytype": "subunitStatus", "dat": "72 F", "measurement": "level", "unit": "hvac"}, "ping": {"entrytype": "subunitStatus", "dat": "60 ms", "measurement": "level", "unit": "comms"}, "invert load": {"entrytype": "subunitStatus", "dat": "402 W", "measurement": "level", "unit": "electric"}, "humidity": {"entrytype": "subunitStatus", "dat": "45%", "measurement": "level", "unit": "hvac"}, "upload": {"entrytype": "subunitStatus", "dat": "8 Mbit/s", "measurement": "level", "unit": "comms"}}'


unitid = '19700111'
uploaded = 'no'
data = {
    'unitid': unitid,
    'uploaded': uploaded,
    'time_stamp': str(datetime.now()),
    'data_list': json_data2,
    }

rq = requests.post(
"https://XXXXX.pythonanywhere.com/XXX/default/api/packed_data.json",
data=data,
auth=auth,
headers={'Connection':'close'}
)

web2py上的代码是标准代码:

def api():  
    response.view = 'generic.'+request.extension
    def GET(*args,**vars):
        patterns = 'auto'
        parser = db.parse_as_rest(patterns,args,vars)
        if parser.status == 200:
            return dict(content=parser.response)
        else:
            raise HTTP(parser.status,parser.error)
    def POST(table_name,**vars):
        return db[table_name].validate_and_insert(**vars)
    def PUT(table_name,record_id,**vars):
        return db(db[table_name]._id==record_id).update(**vars)
    def DELETE(table_name,record_id):
        return db(db[table_name]._id==record_id).delete()
    return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)

我希望输入“ Response [200]”,并将该条目发布到我的packed_data数据库中。我收到“响应[200]”,但没有记录任何记录。

0 个答案:

没有答案