I'm not a software dev; I am self taught and learn through trial and error so this may be clear to some of you whereas I just don't know what I'm doing wrong.
That being said, I have a project I was working on a few months ago... which is now erroring out during runtime. I look at the traceback, and it appears to be complaining about the json decoder:
Traceback (most recent call last):
File "r3ceive.py", line 222, in <module>
beginRec()
File "r3ceive.py", line 59, in beginRec
iterateList()
File "r3ceive.py", line 71, in iterateList
pullConv(id)
File "r3ceive.py", line 77, in pullConv
response=requests.get(url + id, headers=h, params=p).json()
File "C:\Users\mnowicky\.virtualenvs\k3nect_env-VU1MvjZD\lib\site-packages\requests\models.py", line 890, in json
self.content.decode(encoding), **kwargs
File "c:\program files\python37\Lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "c:\program files\python37\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "c:\program files\python37\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)
Here is the line it's complaining about (line 77, the request interestingly):
response=requests.get(url + id, headers=h, params=p).json()
And here is the entire function:
#For each id in reclist.txt, pull their conversation and latest reply
def pullConv(id):
global cached, latest_key, refDict, direction
response=requests.get(url + id, headers=h, params=p).json()
inbound_dict = {}
for item in response['messages']:
conv_id = item['conversationId']
attach = item['attachments']
if conv_id not in inbound_dict:
inbound_dict[conv_id]={item['id'] : {'msg_id' : item['id'], 'body' : item['body']}}
else:
inbound_dict[conv_id][item['id']] = {'msg_id' : item['id'], 'body' : item['body']}
cached=inbound_dict
cached={k: get_latest(cached[k]) for k in cached.keys()}
latest_key=max(cached.keys())
reply=str(cached[latest_key])
z=cached[latest_key]
z=str(z)
# check for attachment
if attach:
attachments(attach, conv_id)
if not attach:
pass
# check direction, that the message is indeed incoming
checkOutgoing(z, id)
if direction=='in':
m=str(refDict[id])
if m!=z:
Logger.recLog('New reponse detected for id: ' + id, 0)
u={id: z}
refDict.update(u)
with open('shelves/recDic.json', 'w') as outfile:
json.dump(refDict, outfile)
needlesNotify(z, id)
else:
pass
So there's got to be something wrong with the json dependency, but I can't update it or anything...
I'm using python 3.7 with pipenv. I have some experience with Node.js so the whole pipenv package management makes sense to me. However I never knew anything about best practice regarding package version management... so this is what my pipfile looks like (lol):
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
mypy = "*"
[packages]
pyodbc = "*"
configparser = "*"
datetime = "*"
requests = "*"
tqdm = "*"
colorama = "*"
progress = "*"
json-decode = "*"
pprint = "*"
json = "*"
pil = "*"
[requires]
python_version = "3.7"
My packages and dependencies are so mis-managed that I can never get a lock on the pipfile to update anything. It appears that it can't locate any version for the json package, and that's why it's erroring, because of the .json() at the end of the request?
When I try to do a pipenv update, or pipenv lock --clear, or anything at all really, I get this:
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: ERROR: Could not find a version that matches json
No versions found
So I guess I'm looking for some guidance and advice... as in, what should I do to try to resolve this. What is the best practice for managing the dependencies and such. What am I doing wrong here?
Thank you for taking a look!