./export.py failing to obtain tokens
I'm trying to use Instaexport in conjunction with Promnesia to index my Instapaper highlights, but am having trouble at the 3rd step under the Setting Up section of the Readme. When I CD to the relevant directory and try to run ./export.py --login and/or python3 export.py --login, it returns an error of
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/export.py", line 6, in <module>
from .exporthelpers.export_helper import Json
ImportError: attempted relative import with no known parent package
I already obtained my oauth_id and oauth_secret, so would like to proceed with the Exporting and User Data steps of the installation process, but need the oauth_token and oauth_token_secret to do so. Thanks!!
Hi!
Hmm I see you're running it from the directory it's installed into -- I guess the readme is slightly misleading, when it says ./export.py, it refers to ./export.py in the root of the repository.
Either way, it's a legacy way of running things, can you try running it as python3 -m instapexport.export --login instead?
Thanks for this update! In this case however I was only provided my OAuth Consumer ID and OAuth Consumer Secret by Instapaper when I followed step 2; what should I put in the secrets.py for "OAUTH_TOKEN" and "OAUTH_TOKEN_SECRET"?
Did you follow step 3? (it's interactive) :) https://github.com/karlicoss/instapexport#setting-up
P.S. ah hmm I see, due to the way it parses arguments, it still requires the parameters. Good catch!
As a workaround, you can just set dummy values for them in secrets.py, e.g.
...
oauth_token = "OAUTH_TOKEN"
oauth_token_secret = "OAUTH_TOKEN_SECRET"
, and then you'll be able to call --login and receive real values for these parameters.
Thanks for your help with this! Step 3 was the part I had issues with in the original post – I tried leaving the dummy data but I still got the issue when I tried running ./export.py --login and ./export.py --login :
Traceback (most recent call last):
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/./export.py", line 6, in <module> from .exporthelpers.export_helper import Json
ImportError: attempted relative import with no known parent package
I was, however, successfully able to use python3 -m instapexport.export --secrets /Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/secrets.py --login to get my oauth_token and oauth_token_secret. I added those to my secerets.py file in addition to my oauth_id and oauth_secret, however when I try running python3 -m instapexport.export --secrets /Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/secrets.py I get the error message
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/export.py", line 96, in <module>
main()
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/export.py", line 67, in main
j = get_json(**params)
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/export.py", line 28, in get_json
user_folders = api.folders()
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 374, in folders
items = json.loads(data.decode('utf-8'))
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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)```
hmm... seems like the API call is failing? does it print anything after by any chance? should be the JSON it failed to parse. If not, can you try running
python3 -m pdb -c continue -m instapexport.export --secrets /Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/secrets.py
, it should fail with the same error, but this time you can type
print(repr(s))
-- this should print the exact thing it failed to process (make sure it doesn't contain anything private before pasting here!)
hmm... seems like the API call is failing? does it print anything after by any chance? should be the JSON it failed to parse.
the Traceback part I quoted is the only thing that prints
If not, can you try running...
Here's what this outputted
Bro13 rwbarat ~/Library/Python/3.9/lib/python/site-packages/instapexport 08:34: python3 -m pdb -c continue -m instapexport.export --secrets /Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/secrets.py
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pdb.py", line 1702, in main
pdb._runmodule(mainpyfile)
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pdb.py", line 1547, in _runmodule
self.run(code)
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/bdb.py", line 580, in run
exec(cmd, globals, locals)
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/export.py", line 2, in <module>
import argparse
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/export.py", line 67, in main
j = get_json(**params)
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapexport/export.py", line 28, in get_json
user_folders = api.folders()
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 374, in folders
items = json.loads(data.decode('utf-8'))
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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)
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py(355)raw_decode()
, it should fail with the same error, but this time you can type print(repr(s))
The only thing that was returned when I typed print(repr(s)) and pressed enter was
(Pdb) print(repr(s))
''
(Pdb)
Ah okay, so it's actually empty string..
Well it's sad, but it seems that Instapaper returns empty response to you for some reason...
I guess we could try debugging it.
Can you try steps from here https://github.com/karlicoss/instapaper#basic-usage in a python3 session and report the results?
The only difference is that for the "Logging in" step instead of email/password login, you should do:
>>> from instapaper import Instapaper as ipaper
>>> i = ipaper(oauth_id, oauth_secret)
>>> i.login_with_token(oauth_token, oauth_token_secret)
(with the oath values you already got before)
>>> i = ipaper(oauth_id, oauth_secret)
When I ran this line, after replacing oauth_id and oauth_secret with my tokens, it said SyntaxError: invalid syntax, with a ^ pointing to the second character in my oauth_secret.
>>> i.login_with_token(oauth_token, oauth_token_secret)
When I ran this line, it gave SyntaxError: invalid syntax, with a ^ pointing to the second digit in oauth_token
huh? did you put your token in the quotes? as in ipaper("some_id", "123secret"), not ipaper(some_id, 123secret)
oh whoops I forgot the quotes in the strings! When I included the quotes I didn't get any error messages after running those 3 commands. When I ran 'marks = i.bookmarks()', I got the following error message
>>> marks = i.bookmarks()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 359, in bookmarks
items = self.bookmarks_raw(folder=folder, limit=limit, have=have)
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 350, in bookmarks_raw
items = json.loads(data.decode('utf-8'))
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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)
When I ran marks[0].html, I got the error message
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 359, in bookmarks
items = self.bookmarks_raw(folder=folder, limit=limit, have=have)
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 350, in bookmarks_raw
items = json.loads(data.decode('utf-8'))
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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)
>>> marks[0].html
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'marks' is not defined
marks[0].text
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 359, in bookmarks
items = self.bookmarks_raw(folder=folder, limit=limit, have=have)
File "/Users/rwbarat/Library/Python/3.9/lib/python/site-packages/instapaper.py", line 350, in bookmarks_raw
items = json.loads(data.decode('utf-8'))
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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)
>>> marks[0].html
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'marks' is not defined
>>> marks[0].text
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'marks' is not defined
Right, seems that the the API just doesn't return anything. I could try debugging further, but would need to do it myself, not sure how to do it over github.
If you trust me with your instapaper credentials (i.e. you don't have anything private/confidential there), perhaps you could email me them?
(just oauth_id, oauth_secret, oauth_token, oauth_token_secret; no need for password).
After I (hopefully!) debug the issue you'd be able to invalidate the old token and generate a new one. Annoying to resort to this, but not sure what's a better way...