我的URL数据赢了';t填写我的SQL数据表Python
我得到这个编译错误我的URL数据赢了';t填写我的SQL数据表Python,python,sql,database,api,pycharm,Python,Sql,Database,Api,Pycharm,我得到这个编译错误 import json import urllib import sqlite3 def loading(): url = 'https://jobs.github.com/positions.json?page=1' # URL for API 1-5json_obj = urllib.urlopen(url) response = urllib.urlopen(url) data = json.load(response) # loads
import json
import urllib
import sqlite3
def loading():
url = 'https://jobs.github.com/positions.json?page=1' # URL for API 1-5json_obj = urllib.urlopen(url)
response = urllib.urlopen(url)
data = json.load(response) # loads the url and set it into data variable
for item in data[0].keys():
return data # Get the keys
# def loading():
# print " LOADING API(s)"
# urllib.urlopen('https://jobs.github.com/positions.json?page=1')
# temp = json.dumps(data[1])
# print (json.dumps(data[1]))
# print (" ")
def createDB(data):
conn = sqlite3.connect('comp.db')
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE IF NOT EXISTS comp
(id text primary key, type text, url text,created_at timestamp, company text, company_url text, location text, title text, description text, how_to_apply text, company_logo text
)''')
temp_values = list(tuple())
for item in data:
list_of_values = [v for k, v in item.items()]
tuple_of_values = tuple(list_of_values)
temp_values.append(tuple_of_values)
#TO DO
# Make sub sets for each category call
# put in category for each ? in table
c.executemany('INSERT INTO comp VALUES (?,?,?,?,?,?,?,?,?,?,?)', temp_values)
conn.commit()
def main():
data = loading()
createDB(data)
main()
回溯(最近一次呼叫最后一次):
文件“/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py”,第43行,在
main()
文件“/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py”,第40行,在main中
数据=加载()
文件“/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py”,第9行,在加载中
data=json.load(response)#加载url并将其设置为数据变量
AttributeError:“模块”对象没有属性“加载”
json.py是否与脚本位于同一文件夹中?我不确定如何进行检查。我使用的是Pycharm IDEPycharm,它可以在项目窗格中显示目录的内容
Traceback (most recent call last):
File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 43, in <module>
main()
File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 40, in main
data = loading()
File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 9, in loading
data = json.load(response) # loads the url and set it into data variable
AttributeError: 'module' object has no attribute 'load'