I'm trying to learn Python and at the same time learn PRAW. I'm trying to run the below from PyCharm and keeping the error that is below. The code below is the basic first tutorial.
import time
import praw
r = praw.Reddit('PRAW related-question monitor by u/_Daimon_ v 1.0.'
'Url: https://praw.readthedocs.org/en/latest/'
'pages/writing_a_bot.html')
r.login()
already_done = []
prawWords = ['praw', 'reddit_api', 'mellort']
while True:
subreddit = r.get_subreddit('learnpython')
for submission in subreddit.get_hot(limit=10):
op_text = submission.selftext.lower()
has_praw = any(string in op_text for string in prawWords)
# Test if it contains a PRAW-related question
if submission.id not in already_done and has_praw:
msg = '[PRAW related thread](%s)' % submission.short_link
r.send_message('_Daimon_', 'PRAW Thread', msg)
already_done.append(submission.id)
time.sleep(1800)
Error
C:\Python34\python.exe C:/Users/Administrator/PycharmProjects/untitled1/Reddit
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled1/Reddit", line 6, in <module>
r.login('rbevans', 'bowstead')
File "C:\Python34\lib\site-packages\praw\__init__.py", line 1266, in login
self.user = self.get_redditor(user)
File "C:\Python34\lib\site-packages\praw\__init__.py", line 890, in get_redditor
return objects.Redditor(self, user_name, *args, **kwargs)
File "C:\Python34\lib\site-packages\praw\objects.py", line 663, in __init__
fetch, info_url)
File "C:\Python34\lib\site-packages\praw\objects.py", line 72, in __init__
self.has_fetched = self._populate(json_dict, fetch)
File "C:\Python34\lib\site-packages\praw\objects.py", line 127, in _populate
json_dict = self._get_json_dict() if fetch else {}
File "C:\Python34\lib\site-packages\praw\objects.py", line 120, in _get_json_dict
as_objects=False)
File "C:\Python34\lib\site-packages\praw\decorators.py", line 161, in wrapped
return_value = function(reddit_session, *args, **kwargs)
File "C:\Python34\lib\site-packages\praw\__init__.py", line 526, in request_json
data = json.loads(response, object_hook=hook)
File "C:\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
sys:1: ResourceWarning: unclosed <socket.socket fd=632, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('172.29.138.114', 50568), raddr=('198.41.208.139', 80)>
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=608, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('172.29.138.114', 50566), raddr=('198.41.208.142', 443)>
C:\Python34\lib\importlib\_bootstrap.py:2150: ImportWarning: sys.meta_path is empty
Process finished with exit code 1
Related
This is what I am running with doit.
def task_tests() -> dict:
"""Runs all tests."""
return {
"actions": ["poetry run pytest"],
}
and When I run it I get this error
doit tests
Traceback (most recent call last):
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/doit_cmd.py", line 294, in run
return command.parse_execute(args)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/cmd_base.py", line 150, in parse_execute
return self.execute(params, args)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/cmd_base.py", line 570, in execute
return self._execute(**exec_params)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/cmd_run.py", line 265, in _execute
return runner.run_all(self.control.task_dispatcher())
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/runner.py", line 254, in run_all
self.run_tasks(task_dispatcher)
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/runner.py", line 217, in run_tasks
if not self.select_task(node, task_dispatcher.tasks):
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/runner.py", line 118, in select_task
if node.ignored_deps or self.dep_manager.status_is_ignore(task):
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/dependency.py", line 594, in status_is_ignore
return self._get(task.name, "ignore:")
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/dependency.py", line 213, in get
self._db[task_id] = self.codec.decode(task_data.decode('utf-8'))
File "/Users/sazzad/Library/Caches/pypoetry/virtualenvs/service-qHFD2Grb-py3.9/lib/python3.9/site-packages/doit/dependency.py", line 60, in decode
return self.decoder.decode(data)
File "/Library/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 "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 1359414 (char 1359413)
I can run other doit tasks but not tests. I can run this command from terminal without any error
I am using an apple MacBook pro [M1 chip]
I've been trying to fix this but couldn't find a fix anywhere, I'm using InstaLoader 4.5.5.
I am getting this error:
Traceback (most recent call last):
File "main.py", line 145, in <module>
attemptRoutine()
File "main.py", line 136, in attemptRoutine
routine()
File "main.py", line 90, in routine
scrapeVideos(username = IG_USERNAME,
File "/media/ubuntu/EE81-0482/Python/auto_Yt/scrape_videos.py", line 18, in scrapeVideos
L.login(username, password)
File "/home/ubuntu/.local/lib/python3.8/site-packages/instaloader/instaloader.py", line 483, in login
self.context.login(user, passwd)
File "/home/ubuntu/.local/lib/python3.8/site-packages/instaloader/instaloadercontext.py", line 224, in login
resp_json = login.json()
File "/usr/lib/python3/dist-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I've been trying to scrape videos from meme pages for a youtube channel, Code taken from:
automated_youtube_channel Github
The code is so simple I don't know how the error can be solved. All the packages has been updated.
import datetime as dt
import yfinance as yf
ticker = 'MSFT'
start_date = dt.datetime(2020,1,1)
data = yf.download(ticker, start_date)
And the error is in .json, I don't have any ideas how this can be solved.
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/multitasking/__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/yfinance/multi.py", line 169, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/yfinance/multi.py", line 181, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/yfinance/base.py", line 157, in history
data = data.json()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/Library/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 "/Library/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)
I made a script with a friend, unluckily the script does not run smoothly. It fails at some point and gives the following error:
Traceback (most recent call last):
File "restClient.py", line 157, in <module>
loop.run_until_complete(task)
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "restClient.py", line 142, in func
available = client.getStockAmount(_product)
File "/root/brandcanyon/BrandCanyonApi/client.py", line 269, in getStockAmount
productId, productVariantId = self.findProductIdAndVariantId(product.name, product.size)
File "/root/brandcanyon/BrandCanyonApi/client.py", line 168, in findProductIdAndVariantId
product = self.getProductById(productId)
File "/root/brandcanyon/BrandCanyonApi/client.py", line 136, in getProductById
product = response.json()['data']
File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.7/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)
The restClient.py File that the script is talking about is the following:
while True:
for product in page1:
for variant in product.attributes['variants']:
print(variant.attributes)
print(product.attributes['title'])
print(variant.attributes['option2'])
_product = Product(
name = product.attributes['title'],
size = variant.attributes['option2']
)
shopify.InventoryLevel.set(
location_id = location_id,
inventory_item_id = variant.inventory_item_id,
available = client.getStockAmount(_product)
)
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
if page1.has_next_page():
page1 = page1.next_page()
else:
break
print("Inventory Updated - Waiting 350 seconds for next Update")
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
await asyncio.sleep(20)
loop = asyncio.get_event_loop()
task = loop.create_task(func())
try:
loop.run_until_complete(task)
except asyncio.CancelledError:
pass
Do you know the error? Can you help me out?
Thank you so much!
I am using jupyter notebook, but R kernel(IRkernel) sometimes die when inputting Kanji(japanese multibyte chars).
I've tried a few Kanji, and found that IRkernel dies when using specific Kanji characters. For example, '十', '能', '表', etc.
Above image is R concole. Below is Python console.
It doesen't work with R kernel only.
[I 12:44:58.387 LabApp] Kernel started: 9bbe39ea-ef5a-40c3-ae71-fa071874fc79
-- Attaching packages --------------------------------------- tidyverse 1.2.1 --
tibble 1.4.2 purrr 0.2.5
tidyr 0.8.2 dplyr 0.7.8
readr 1.1.1 forcats 0.3.0
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::between() masks data.table::between()
x readr::col_factor() masks scales::col_factor()
x purrr::discard() masks scales::discard()
x dplyr::first() masks data.table::first()
x dplyr::last() masks data.table::last()
x purrr::transpose() masks data.table::transpose()
[I 12:45:00.626 LabApp] Adapting to protocol v5.0 for kernel 9bbe39ea-ef5a-40c3-ae71-fa071874fc79
[E 12:45:09.377 LabApp] Uncaught exception in ZMQStream callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 376, in record_activity
msg = session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
[E 12:45:09.377 LabApp] Uncaught exception in zmqstream callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 376, in record_activity
msg = session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
Exception in callback BaseAsyncIOLoop._handle_events(1596, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(1596, 1)>
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\asyncio\events.py", line 145, in _run
self._callback(*self._args)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 117, in _handle_events
handler_func(fileobj, events)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 376, in record_activity
msg = session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
[E 12:45:09.377 LabApp] Uncaught exception GET /api/kernels/9bbe39ea-ef5a-40c3-ae71-fa071874fc79/channels?session_id=89b50480637cb8ce56024a508a3e4c34 (::1)
HTTPServerRequest(protocol='http', host='localhost:9999', method='GET', uri='/api/kernels/9bbe39ea-ef5a-40c3-ae71-fa071874fc79/channels?session_id=89b50480637cb8ce56024a508a3e4c34', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\web.py", line 1499, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "<string>", line 4, in raise_exc_info
File "C:\ProgramData\Anaconda3\lib\site-packages\tornado\stack_context.py", line 315, in wrapped
ret = fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 196, in <lambda>
self.on_recv(lambda msg: callback(self, msg), copy=copy)
File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\handlers.py", line 313, in _on_zmq_reply
msg = self.session.deserialize(fed_msg_list)
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 933, in deserialize
message['content'] = self.unpack(msg_list[4])
File "C:\ProgramData\Anaconda3\lib\site-packages\jupyter_client\session.py", line 105, in <lambda>
json_unpacker = lambda s: jsonapi.loads(s)
File "C:\ProgramData\Anaconda3\lib\site-packages\zmq\utils\jsonapi.py", line 56, in loads
return jsonmod.loads(s, **kwargs)
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 25 (char 24)
And this code works on native R environment fine, so I think this is IRkernel problem.
Thanks.
*Version
OS:Win 10
jupyter-lab:0.32.1
IRkernel:'0.8.14.9000'