Error: ValueError: No JSON object could be decoded
Dear mikejs,
I have the following problem, if I want to use the get_zci() method I get a random
Traceback (most recent call last):
File "get-search-engine-hits.py", line 12, in <module>
search_result = duckduckgo.get_zci(content)
File "build/bdist.linux-x86_64/egg/duckduckgo.py", line 144, in get_zci
File "build/bdist.linux-x86_64/egg/duckduckgo.py", line 55, in query
File "/usr/lib64/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
message and afterwards I cannot use the library again because if the error shows up once, it ever shows up again (meaning even if I quit out of python interpreter and start a new session - the error persists). I found out that if I use the query method in between I can somehow reset this behaviour and then it works again. Here is the problematic code (I am not behind a proxy or firewall)
r-packages-debs.txt
acepack
ade4
annotate
AnnotationDbi
AnnotationHub
ape
assertthat
base64enc
BH
Biobase
BiocGenerics
BiocInstaller
BiocParallel
BiocStyle
biomaRt
Biostrings
biovizBase
bitops
broom
BSgenome
caTools
chron
coda
colorspace
corpcor
crayon
cubature
curl
data.table
DBI
DESeq2
problematic script
not_working.py
import duckduckgo,time
fname = "./r-packages-debs.txt"
with open(fname) as fp:
for line in fp:
content = line.strip() + " R"
search_result = duckduckgo.get_zci(content)
print content + "\t" + search_result
time.sleep(5)
after running the screen and provoking the error for the first time, the error shows up every time you request something ever again until you use the query() method. This somehow "magically" resets the problem
introducing query() method avoids the problem completely
working.py
import duckduckgo,time
fname = "./r-packages-debs.txt"
with open(fname) as fp:
for line in fp:
# this "dummy request" avoids the problem but i dunno why
duckduckgo.query("foo")
content = line.strip() + " R"
search_result = duckduckgo.get_zci(content)
print content + "\t" + search_result
time.sleep(5)
so somehow duckduckgo seems to save some information about former requests from the IP when using the get_zci() method or something is saved temporarily on the HDD somewhere.
Even i had the same problem. Try updating duckduckgo module use this in the terminal
pip install duckduckgo2 This solved the error form me
@OliPelz , does @jkthaha 's answer solve your problem? If so, please close this issue.