错误消息:Http未定义/API导入Python

错误消息:Http未定义/API导入Python,python,json,pandas,api,Python,Json,Pandas,Api,我正在尝试导入Json API的URL,但收到错误消息: --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-18-5f40dac6d9a4> in <module> 1 # get

我正在尝试导入Json API的URL,但收到错误消息:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-18-5f40dac6d9a4> in <module>
      1 # get data from the API
      2 url = 'https://admin.appnext.com/offerApi.aspx?pimg=1&city=1&ua=1&id=5da11d20-0a32-4852-8233-39b711a360a9'
----> 3 r = http.request('GET', url)
      4 r.status

NameError: name 'http' is not defined
没有要导入的问题

# get data from the API
url = 'https://admin.appnext.com/offerApi.aspx?pimg=1&city=1&ua=1&id=5da11d20-0a32-4852-8233-39b711a360a9'
r = http.request('GET', url)
r.status
有人知道会有什么问题吗


提前感谢

您没有在显示的代码中的任何地方定义变量http。首先需要从连接池管理器实例化一个新请求,然后才能执行该请求:

#数据检索
导入urllib3
从urllib3导入请求
#json数据
导入json
#熊猫数据帧
作为pd进口熊猫
#从API获取数据
http=urllib3.PoolManager()
url='1〕https://admin.appnext.com/offerApi.aspx?pimg=1&city=1&ua=1&id=5da11d20-0a32-4852-8233-39b711a360a9'
r=http.request('GET',url)
r、 地位

仅供参考:

您的代码中未定义HTTP,因此您不能使用它。我建议您查看python中关于“请求”模块的指南,并查看他们关于如何执行请求的示例:

然后,您可以像这样执行请求:

#  data retrieval
import requests
# json data
import json
# pandas dataframes
import pandas as pd

url = 'https://admin.appnext.com/offerApi.aspx?pimg=1&city=1&ua=1&id=5da11d20-0a32-4852-8233-39b711a360a9'
r = requests.get(url)
print(r.status)
import urllib.request

url = 'https://admin.appnext.com/offerApi.aspx?pimg=1&city=1&ua=1&id=5da11d20-0a32-4852-8233-39b711a360a9'
x = urllib.request.urlopen(url)
print(x.read())

您需要使用
urllib.request.urlopen()

代码如下所示:

#  data retrieval
import requests
# json data
import json
# pandas dataframes
import pandas as pd

url = 'https://admin.appnext.com/offerApi.aspx?pimg=1&city=1&ua=1&id=5da11d20-0a32-4852-8233-39b711a360a9'
r = requests.get(url)
print(r.status)
import urllib.request

url = 'https://admin.appnext.com/offerApi.aspx?pimg=1&city=1&ua=1&id=5da11d20-0a32-4852-8233-39b711a360a9'
x = urllib.request.urlopen(url)
print(x.read())

谢谢,这很有帮助:)