[英]JSONDecodeError: Expecting value: line 1 column 1 (char 0). Error on using bing search
I have a simple script to get urls from bing search. 我有一个简单的脚本,可以从必应搜索中获取网址。
import bingsearch
bingsearch.API_KEY='mykey'
r = bingsearch.request("JohnDalton")
print r.status_code
print r[0]['Url']
The bingsearch.py file is: bingsearch.py文件为:
import requests
import urllib2
URL = "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query='%(query)s'&$top=50&$format=json"
API_KEY = 'mykey'
def request(query, **params):
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
return r.json()['d']['results']
How do i avoid the error mentioned before. 我如何避免前面提到的错误。 Thanks.
谢谢。
It's an auth problem, you are not getting any results so nothing to decode. 这是一个身份验证问题,您没有得到任何结果,因此无法解码。
this might be the error it gets: The authorization type you provided is not supported. 这可能是它得到的错误:不支持您提供的授权类型。 Only Basic and OAuth are supported 401
仅支持基本和OAuth 401
I think in auth dictionary 我认为在auth字典中
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
you should pass username as well instead of empty string. 您还应该传递用户名,而不是空字符串。
Edit: 编辑:
Looks like username and passwd both are identical for azure api. 看起来用户名和passwd对于azure api都是相同的。 Try passing
尝试通过
r = requests.get(URL % {'query': query}, auth=(API_KEY, API_KEY))
Edit2: 编辑2:
Ok whats the output of this 好的,这是什么输出
import requests
URL = "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query='%(query)s'&$top=50&$format=json"
API_KEY = 'mykey'
def request(query, **params):
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
print r.content, r.status_code
return r.json()['d']['results']
r = request("JohnDalton")
print r.status_code
print r[0]['Url']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.