我正在尝试从服务器获取数据并存储到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表