0

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')
A B
  • 87
  • 1
  • 7
  • Please show the problem in the code. – NTSwizzle Jun 15 '21 at 14:45
  • @NTSwizzle Hey, is that better? Sorry, I'm New to Stackoverflow. – A B Jun 15 '21 at 14:50
  • 1
    What’s the file structure of your project? Is main.py in the same directory as your tkinter file? – NTSwizzle Jun 15 '21 at 15:05
  • Yes, all of my files are within the same directory – A B Jun 15 '21 at 15:08
  • Is this the entire error message? – Delrius Euphoria Jun 15 '21 at 15:38
  • It looks like part of the error is missing. – Bryan Oakley Jun 15 '21 at 15:43
  • Hey, I updated both the main file and the error messages to show the entirety of them. I only posted parts I thought were relavent beforehand. – A B Jun 15 '21 at 15:54
  • Btw the code does work by itself (I tested it with 2 dummy files before maing the GUI and it worked perfectly), after I made the GUI the code would also work but sometimes not (Giving the lines of error in the post). Therefore I'm Assuming that I didn't do something properly with the tkinter code as that was the only thing I added. The tkinter file really only interacts with main.py by calling the only defined function in it, so I'm not sure exactly where I messed up? – A B Jun 15 '21 at 16:00
  • 1
    https://stackoverflow.com/questions/62384020/python-3-7-urllib-request-doesnt-follow-redirect-url – 8349697 Jun 15 '21 at 16:39
  • @8349697 Thanks a bunch! Figured it out with the above link, helped a lot. The codes working again – A B Jun 15 '21 at 20:31

0 Answers0