Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不准确的数据被打孔到heroku postgresql表_Python_Postgresql_Heroku_Flask Sqlalchemy - Fatal编程技术网

Python 不准确的数据被打孔到heroku postgresql表

Python 不准确的数据被打孔到heroku postgresql表,python,postgresql,heroku,flask-sqlalchemy,Python,Postgresql,Heroku,Flask Sqlalchemy,您好,我正在通过自己制作一个应用程序来学习Flask/SqlAlchemy,但是我注意到有时会出现不准确的数据,请参阅通过访问此应用程序生成的数据剪辑 在数据剪辑条目中,使用visitorIdN4PT3R0ZQ是不正确的。例如,我在Windows phone中键入URL打开了页面,但输入的数据是我正在查看数据剪辑页面的iPhone或我以前访问过该页面 以下是此表中更新的代码visitor def updateOrInsertToTable(user_agent, visitorInfo):

您好,我正在通过自己制作一个应用程序来学习Flask/SqlAlchemy,但是我注意到有时会出现不准确的数据,请参阅通过访问此应用程序生成的数据剪辑

在数据剪辑条目中,使用
visitorId
N4PT3R0ZQ
是不正确的。例如,我在Windows phone中键入URL打开了页面,但输入的数据是我正在查看数据剪辑页面的iPhone或我以前访问过该页面

以下是此表中更新的代码
visitor

def updateOrInsertToTable(user_agent, visitorInfo):
    """ Updates the table if visitor id exists else insert for new visitor
        Arguments: 
            user_agent (request.user_agent): request.user_agent object
            visitorInfo (dict): key value pair of visitor information 
    """
    visitorId =  visitorInfo["visitorId"]
    visitorIp = visitorInfo["clientIP"]
    language = visitorInfo["language"]
    referrer = visitorInfo["referrer"]
    coord_errorcode = visitorInfo.get("coord_errorcode", None)
    cl_lat = visitorInfo.get("cl_lat", 0.0)
    cl_lng = visitorInfo.get("cl_lng", 0.0)
    tz = _utils.getTimezoneFromIP(visitorIp)
    dtWithZone = _datetime.now(pytz.timezone(tz))
    visitorModel = Visitor(
        user_agent.platform,
        user_agent.browser, 
        dtWithZone, visitorId, 
        cl_lat, cl_lng,
        language, referrer,
        user_agent.version, 
        visitorIp,
        tz
    )
    existing = visitorModel.query.get(visitorId)

    if existing:
        existing.version = user_agent.version
        existing.cl_lat = float(cl_lat)
        existing.cl_lng = float(cl_lng)
        existing.ip = visitorIp
        existing.language = language
        existing.referrer = referrer
        existing.count = existing.count + 1
        existing.coord_errorcode = coord_errorcode
        existing.visitdatetime = dtWithZone
        db.session.commit()
    else:
        columnValues = {
            "platform" : user_agent.platform,
            "browser" : user_agent.browser,
            "visitorId" : visitorId,
            "cl_lat" : cl_lat,
            "cl_lng" : cl_lng,
            "language" : user_agent.language,
            "referrer" : referrer,
            "version" : user_agent.version,
            "count" : 1,
            "coord_errorcode": coord_errorcode,
            "ip" : visitorIp,
            "visitdatetime" : dtWithZone,
            "timezone": tz
        }
        insertIntoTable(dtWithZone, 'visitor', columnValues)



def insertIntoTable(dtWithZone, tableName, columValues):
    """ Insert into table with provided date time and time zone information.
    """
    db_uri = app.config["SQLALCHEMY_DATABASE_URI"]
    engine = create_engine(db_uri, connect_args={"options": "-c timezone={}".format(dtWithZone.timetz().tzinfo.zone)})
    meta = MetaData(engine, reflect=True)
    table = meta.tables[tableName]
    ins = table.insert().values(**columValues)
    conn = engine.connect()
    conn.execute(ins)
    conn.close()
我的方法有什么问题吗?还是我完全做错了


非常感谢您的帮助。

什么数据不准确?对不起,我已经更新了帖子。带有visitorId的条目
N4PT3R0ZQ
什么数据不准确?对不起,我已经更新了帖子。带有visitorId的条目
N4PT3R0ZQ