[ERROR] json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Karltroid opened this issue · 1 comments
What's Happening
I am getting a json.decoder.JSONDecodeError
when python executes its native decoder, specifically from the line obj, end = self.raw_decode(s, idx=_w(s, 0).end())
. When I get rid of the try catch it says this line TypeError: cannot unpack non-iterable NoneType object
. From digging in instapy's src code this all stems from self.cookie = json.loads(cookie, object_hook=self.from_json, strict=False)
. I've been looking around for days and found no solution that works. If anyone can help that would be amazing.
import time
import praw
import urllib.request
from selenium import webdriver
from instapy_cli import client
reddit = praw.Reddit(client_id='hidden4post', \
client_secret='hidden4post', \
user_agent='hidden4post', \
username='hidden4post', \
password='hidden4post')
posted = []
def getpost(postnum=1):
for submission in reddit.subreddit('hidden4post').hot(limit=postnum): # get x amount of the top posts
if submission.title not in posted: # check if post has been posted before
posted.append(submission.title) # IF it hasn't, add it to posted list
post(submission, postnum) # and post it
time.sleep(7200) # wait some time before the next post
getpost(1) # find a new post
getpost(postnum+1) # IF it has, run getpost again with one
# extra post in the search queue
def post(newpost, i):
driver = webdriver.Chrome("venv/chromedriver.exe")
driver.get("https://clipr.xyz/")
time.sleep(1)
search_input_box = driver.find_element_by_name("clip_url")
search_input_box.send_keys(newpost.url)
submit_clip_button = driver.find_element_by_css_selector("button.clipr-button")
submit_clip_button.click()
time.sleep(1)
# thumbnail = driver.find_elements_by_tag_name("img")
links = driver.find_elements_by_tag_name("a")
try:
# urllib.request.urlretrieve(thumbnail[1].get_attribute('src'), 'thumbnails/' + str(len(posted)) + '.jpg')
urllib.request.urlretrieve(links[10].get_attribute('href'), 'videos/' + str(len(posted)) + '.mp4')
except:
print("couldn't download video or thumbnail.")
getpost(i + 1) # if downloading video isn't working, skip this post and go to the next.
finally:
with client('hidden4post', 'hidden4post', cookie='cookies/hidden4post_ig.json') as instagram:
instagram.get_cookie()
instagram.upload('videos/' + str(len(posted)) + '.mp4', newpost.title)
print("Posted: " + newpost.title)
getpost()
Expected behavior
For everything to run smoothly and post the video to Instagram
Logs
Traceback (most recent call last):
File "E:/PyCharm Community Edition 2018.3.2/_Projects/TopToInsta/main.py", line 53, in <module>
getpost()
File "E:/PyCharm Community Edition 2018.3.2/_Projects/TopToInsta/main.py", line 20, in getpost
post(submission, postnum) # and post it
File "E:/PyCharm Community Edition 2018.3.2/_Projects/TopToInsta/main.py", line 47, in post
with client('hidden4Post', 'hidden4Post', cookie='cookies/hidden4Post.json') as instagram:
File "E:\PyCharm Community Edition 2018.3.2\_Projects\TopToInsta\venv\lib\site-packages\instapy_cli\__init__.py", line 5, in client
return cli(*args, **kwargs)
File "E:\PyCharm Community Edition 2018.3.2\_Projects\TopToInsta\venv\lib\site-packages\instapy_cli\cli.py", line 15, in __init__
self.cookie = json.loads(cookie, object_hook=self.from_json, strict=False) # CAUSE OF ERROR
File "C:\Users\Karlt\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 361, in loads
return cls(**kw).decode(s)
File "C:\Users\Karlt\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Karlt\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Env:
- OS: Windows 10 v1903
- Python: 3.7
- instapy-cli Version: 0.0.12
replace your exceptions
it will narrow down whats the error is
also import Json
with this:
except Exception as e:
print(e)
pass