Currently, I am working on writing my first serious Python script. It is ugly right now, but that is to be expected. The plan is to write small parts and then build more around them, cleaning up the code as I go. It’s slow and slightly tedious at times, but can be exhilarating when stuff starts working.
I want to start documenting my progress so that I can look back and see where I have grown, where I have failed and where I have succeeded. I welcome any input on how to correct bad code, fix errors, or generally clean up the script.
Also, I am just getting started with github, so be patient if my Markdown and version control is not the best.
The purpose of the program is to be able to scan items in my kitchen and create an inventory list for myself. Right now, the barcode has to be entered manually because I am more interested in it working than I am about scanner-gun functionality. We will cross that bridge later.
I have it mostly working in a simplistic manner, but I am trying to account for errors when a barcode is invalid and gives a 404 error. That is pretty much where my head will be all day. Also, if anyone knows a robust, free UPC database with a decent API, I am open to suggestions.
What I am currently run into is that the error code for a 404 happens and urllib.error shows it as an error, however it also shows about 6 other errors, all related to the fact that I received a 404. If anyone out there knows how this happens or a good way to correct, I am all ears.
[bran8219@fedora-workstation python]$ python3 kitchen_inventory.py Enter item 9781491901434 Traceback (most recent call last): File "kitchen_inventory.py", line 53, in <module> request(combined) File "kitchen_inventory.py", line 28, in request f = opener.open(combined) File "/usr/lib64/python3.6/urllib/request.py", line 532, in open response = meth(req, response) File "/usr/lib64/python3.6/urllib/request.py", line 642, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib64/python3.6/urllib/request.py", line 570, in error return self._call_chain(*args) File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain result = func(*args) File "/usr/lib64/python3.6/urllib/request.py", line 650, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found