如何使用python将URL响应数据存储到PSQL数据库中

时间:2018-12-11 12:22:37

标签: python python-3.x psql

我正在尝试从服务器获取数据并存储到python中的变量中。如何从PSQL数据库的存储变量中传递数据。

我到目前为止已经尝试过

import json
import requests
from flask import Flask
import psycopg2
from flask_cors import CORS, cross_origin
def data():

        new_url= "http://someurl.com"
        data = ''
        response = requests.get(new_url, data=data,headers={"Content-Type": "application/json", "X-Query-Key":"12345678" })

        responseText = response.text
        conn = psycopg2.connect(database="database", user = "postgres",  password = "postgres",host = "127.0.0.1", port = "5432")

        print "Opened database successfully"

        cur = conn.cursor()

        cur.execute(''' CREATE TABLE testdb(AppID INT NOT NULL,
                                      USAGE  INT NOT NULL,
                                      AppName TEXT NOT NULL,
                                      ENVIRONMENTNAME TEXT NOT NULL);''')
        print "Table Created successfully"
        conn.commit()
        conn.close()

如何使用Python将响应变量数据传递到PSQL中的testdb表

0 个答案:

没有答案