CS50 Pset9 Finance TraceBack, FileNotFoundError, AttributeError [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Pset9 Finance, please help! When I put my API_Key and run flask, I get these errors that I haven't seen before and don't know how to fix:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/cachelib/file.py", line 219, in delete
os.remove(self._get_filename(key))
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmplxzjvek9/f65da5cfc2b86410e5c673fb6ba2227e'
I have been stuck for the past 2 hours trying to fix this. I tried to ignore them and start the problem set by doing the register part and when I test it I get more issues (AttributeError: 'str' object has no attribute 'get') as you can see. Please help!
enter image description here
enter image description here
enter image description here

As the error message states, request.method is a string, so you can't call the .get() method on it. That method is not defined for strings.
I am not familiar with CS50's problem sets. That being said, it appears that you're trying to access parameters associated with the request on lines 124-126, which is the location of your issue.
For query parameters, use request.args.get('...').
For body parameters, use request.form.get('...').

Related

Python code will only print first line while using input [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 11 months ago.
Improve this question
I am attempting to print the code, but only the first line shows up in the module when ran.
I tried moving lines around entirely but couldn't figure it out. The code is below
num1=input("10")
num2=input("50")
try:
print(int(num1)+int(num2))
except:
print("one of those is not a number")
It will only show 10 on the module.
You seem to be confused on how input() works. The string you provide is printed and what you type into the terminal after it is returned to the variable. If you have no way to type to the program, then input() is not what you're looking for. For more help, the docs for input() can be found here: https://docs.python.org/3/library/functions.html#input
I don't understand what kind of problem are you having here, so I will suggest a few solution to the potential problems you are trying to fix.
The other lines are not printed : looks like that you are a little bit confused about the input() method. See this to learn about : https://docs.python.org/3/library/functions.html#input
The program does not run : the program is unindented and it's mandatory to indent the code in Python, so try to give a tab in the try "body" and in the except "body".

I am stuck at TypeError in tkinter. How to fix it? Please guide me [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I was making a python reader project and wanted to make a python reader (In which the python will read what you wrote in the entry) it works fine but when I write something in the entry it gives me a type error:
and my code:
The problem is somewhere after clicking a read button before that it works just like I want but after clicking the button the problem happens.
Your function funcation is defined to be given str in line 18
def funcation(str):
but you're calling the function without any arguments from reader_btn in line 38: funcation
what you want to do is passing the text variable containing the string like
command=lambda: funcation(text)
from your reader_btn
EDIT:
or probably better read the value of your entry when the button is pressed:
command=lambda: funcation(text_place.get())
thanks to quamrana for pointing that out

Failing to load json file into Google Colab [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am performing a machine learning implementation on a data given in json format.
I haven't tried much because I have no experience.
My code to read is:
with open('attempts.json') as my_file:
d = json.load(my_file)
I am getting error like:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I have replaced my attempts.json file which was 260mb to grades.json which is 12kb but still having same problem.
Your json file must have content and the format is correct.
Based on this error, I think your json file is empty.

“How to fix ‘NoneType' object is not subscriptable”

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 18 hours ago.
Improve this question
I am trying to get product information from Amazon.com.
I searched for some codes on the internet and I've found one. I've tried to fix bugs in the code but I stuck with the one below. It seems that there is something wrong with the last line in the code below because I am getting this error: 'NoneType' object is not subscriptable
for asin in asin_array:
item_array=[] #An array to store details of a single product.
amazon_url="https://www.amazon.com/dp/"+asin #The general structure of a url
response = session.get(amazon_url, headers=headers, verify=False) #get the response
item_array.append(response.html.search('a-color-price">${}<')[0]) #Extracting the price
Because your response is None.
Basically, you trying this
print(None[0])
and its not possible
check your response or searching tag maybe its not available
You can check it before extract:
price_data = response.html.search('a-color-price">${}<')
if price_data:
item_array.append(price_data[0])

import threading not working python 2.7 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am trying to use threading in an upcoming project but I can't get it working. I've tried running the 2nd example on http://www.tutorialspoint.com/python/python_multithreading.htm, which I imagine is working code, but I get the error...
Traceback (most recent call last):
File "C:/Python27/threads/threading.py", line 3, in <module>
import threading2
File "C:\Python27\lib\site-packages\threading2\__init__.py", line 49, in <module>
from threading import _active,_DummyThread
File "C:\Python27\threads\threading.py", line 8, in <module>
class myThread (threading2.Thread):
AttributeError: 'module' object has no attribute 'Thread'
Whats going on? It seems like there is no module named threading. I've looked everywhere to find it. Does anyone know where I can find this module and how to install it?
You called your own file threading and now you're importing your own script and that's not what you want. Please do not use the names of existing packages/modules for your own scripts.
When the code in threading2.py tries to import threading, Python first looks for an already-imported module with that name. If that fails, it looks through each location in sys.path for a file named threading.py that it can load. Normally, it will find the one in the standard library. But if you have a file named threading.py in the same location as the script—or if it's the name of the script itself—Python will find that one first, and load it instead.
Also, don't save your own scripts in the folder where Python is installed.

Categories