用树莓派python获取token报错
哈灬咳 发布于2020-08 浏览:5067 回复:2
0
收藏

新人求助各位前辈,十分感谢

代码如下:

# encoding:utf-8
import requests

# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【官网获取的AK】&client_secret=【官网获取的SK】'
response = requests.get(host)
if response:
print(response.json())

AK和SK都有修改成自己的应用

在控制台执行后出现

Traceback (most recent call last):
File "/home/pi/Desktop/token.py", line 2, in
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in
import urllib3
File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 8, in
from .connectionpool import (
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 3, in
import logging
File "/usr/lib/python3.7/logging/__init__.py", line 26, in
import sys, os, time, io, traceback, warnings, weakref, collections.abc
File "/usr/lib/python3.7/traceback.py", line 5, in
import linecache
File "/usr/lib/python3.7/linecache.py", line 11, in
import tokenize
File "/usr/lib/python3.7/tokenize.py", line 35, in
from token import *
File "/home/pi/Desktop/token.py", line 6, in
response = requests.get(host)
AttributeError: module 'requests' has no attribute 'get'

收藏
点赞
0
个赞
共2条回复 最后由哈灬咳回复于2020-08
#3哈灬咳回复于2020-08
#2 用户已被禁言回复
错误是什么呢?百度接口只要请求到。不管成功失败都会返回json格式字符串内容。 ak sk分别指的是API Key 和 Secret Key  不是Access Key Secret Key
展开

嗯感谢你的指教,ak和sk是没问题的,报错信息是AttributeError: module 'requests' has no attribute 'get',并未返回json格式的内容

0
#2用户已被禁言回复于2020-08

错误是什么呢?百度接口只要请求到。不管成功失败都会返回json格式字符串内容。

ak sk分别指的是API Key 和 Secret Key  不是Access Key Secret Key

2
TOP
切换版块