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!
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]
stock_df = pd.DataFrame()
stock = []
stock = yf.download(ticker, start= start_date, end= end_date, progress= False)
stock_df= stock_df.append(stock, sort= False)
stock_df['Symbol'] = ticker
Exception in thread Thread-4:
Traceback (most recent call last):
File "/opt/anaconda3/envs/learn-env/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/opt/anaconda3/envs/learn-env/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/multitasking/__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/yfinance/multi.py", line 166, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/yfinance/multi.py", line 178, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/yfinance/base.py", line 155, in history
data = data.json()
File "/opt/anaconda3/envs/learn-env/lib/python3.8/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/opt/anaconda3/envs/learn-env/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/anaconda3/envs/learn-env/lib/python3.8/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 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)
So I got the JSONDecodeError in json.load() while everything seems to be right.
My code:
def write(name: str, text):
try:
with open("C:/Users/FlexGames/Desktop/Programming/Discord Bot/New Bot/banned.json", "w") as bannedload:
bannedjson[name] = text
json.dump(bannedjson, bannedload)
except NameError:
_load(jsonfile)
return write(name, text, jsonfile)
def _load():
global bannedjson, bannedload
with open("C:/Users/FlexGames/Desktop/Programming/Discord Bot/New Bot/banned.json", "r") as bannedload:
bannedjson = json.load(bannedload)
JSON File:
{
"banned": []
}
Error Output:
Traceback (most recent call last):
File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\main.py", line 77, in on_message
await ban.user(message)
File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\New_Functions\ban.py", line 11, in user
jsonhandle.write("banned", int(content[1]))
File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\Functions\jsonhandle.py", line 27, in write
_load(jsonfile)
File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\Functions\jsonhandle.py", line 42, in _load
bannedjson = json.load(bannedload)
File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\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)
Most "solutions" I found in the internet were faults like .loads() or large and lower case faults or something like this but not this error in this context
So the solution was like SiHa said something was broken with the path, I don't know what exactly but as I removed the whole path but the file it worked 🤷♂️
I have a school schedule in my program, and when I use
import json
if choice == "Schedule":
with open("Schedule.json", "r") as schedule_file:
schedule_output = json.load(schedule_file)
schedule_choice = input('\nDo you want to exit or change the schedule?\n')
The problem comes up:
Traceback (most recent call last):
File "practice.py", line 92, in <module>
schedule_output = json.load(schedule_file)
File "C:\Users\Samwise\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Users\Samwise\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\Samwise\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Samwise\AppData\Local\Programs\Python\Python38\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)
I tried to change the encoding, but it didn't help me.