I'm new to tkinter and I've looked online for help with this but can't find it. I cannot seem to find the error in my code, it points to a function in my main python file yet that function is clearly defined. I have attached pictures of the error message alongside the call to the fucntion and file that follow up in the error message.
I can't seem to figure out what the problem is, Seems the error comes from when the user uploads a file into the program by clicking the button whihc triggers the UploadAction function in the tkinter file, which then goes on to call the read_f fucntion defined in the main python file. I'm importing the right files and the fucntion main.read_f is defined in the main python file. Not sure what's causing this?
Note: The code randomly decides to work sometimes and will not display an error, yet seemingly randomly do so.
Any help or a point in the right direction would be appreciated!
Thanks
The Error Message:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "c:/Users/ripta/Desktop/CODING/CSV_Upload/tk_app.py", line 9, in UploadAction
main.read_f(filename)
File "c:\Users\ripta\Desktop\CODING\CSV_Upload\main.py", line 9, in read_f
brand = search_tm.get_brand(prod_page)
File "c:\Users\ripta\Desktop\CODING\CSV_Upload\search_tm.py", line 17, in get_brand
page = prod_class.prod_page(link)
File "c:\Users\ripta\Desktop\CODING\CSV_Upload\prod_class.py", line 39, in __init__
with urllib.request.urlopen(req) as request_page:
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 532, in open
response = meth(req, response)
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 564, in error
result = self._call_chain(*args)
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 504, in _call_chain
result = func(*args)
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 735, in http_error_302
new = self.redirect_request(req, fp, code, msg, headers, newurl)
File "C:\Users\ripta\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 673, in redirect_request
raise HTTPError(req.full_url, code, msg, headers, fp)
urllib.error.HTTPError: HTTP Error 307: Temporary Redirect
The Tkinter file:
import tkinter as tk
import main
from tkinter import filedialog
from tkinter.constants import X, Y
def UploadAction(event=None):
filename = filedialog.askopenfilename()
print('Selected:', filename)
main.read_f(filename)
root = tk.Tk()
root.title('Sticker TM')
root.geometry('350x350')
root.iconbitmap('C:/Users/ripta/Desktop/CODING/CSV_Upload/trademark_icon.ico')
T = tk.Text(root, height=1, width=35)
T.pack()
T.insert(tk.END, "Make sure the file is not open")
button = tk.Button(root, text='Select CSV file', command=UploadAction)
button.pack(side='bottom', pady= '150')
root.mainloop()
The main python file:
import trademarkia_scrap
import file_upload
import search_tm
import pandas as pd
from pandas.io.parsers import read_csv
def read_f (given_file):
df = pd.read_csv(given_file)
prod_page = file_upload.links(df)
brand = search_tm.get_brand(prod_page)
split = search_tm.split_brand(brand)
url_end = search_tm.get_url(split)
tm_link = search_tm.get_tm_url_link(url_end)
reg = trademarkia_scrap.get_reg_status(tm_link)
print(reg)
df["TradeMark"] = reg
df.to_csv(given_file)
print('Done')