Forums

Updates to my code are not showing up in my web app

My web app (halphillips.pythonanywhere.com) is a simple app that uses a button to update some text in a Google spreadsheet. I've just made some changes to my code, and I'm fairly certain that the changes themselves were made correctly (and will share the relevant portions below just in case). However, the web app seems to still be implementing the old version of the code. Is there something I need to do in order to deploy the changes?

I made the changes via the Python Anywhere web interface, i.e. https://www.pythonanywhere.com/user/halphillips/files/home/halphillips/bklynclay/bklynclay/bklynclay7.py?edit

Below is the relevant portion of the code, followed by a list of the changes I made.

CODE:

for index, row in df.iterrows():
    shift_class = row['What type of coverage are you submitting?'].strip()
    date = row['What date is being covered?']
    name1 = row['What is the first and last name of the person who will be covering this shift / class?']
    name2 = row['What is the first and last name of the person who normally covers this shift / teaches this class?']
    class_foh_shift_tech_shift = row['What type of coverage are you submitting?']
    start_time = row['What time does the covered shift/class begin?'].strftime("%I:%M %p")
    end_time = row['What time does the covered shift/class end?'].strftime("%I:%M %p")
    location = row['At which BKLYN CLAY location does your shift take place?']

    if shift_class == 'Teaching a class':
        class_foh_shift_tech_shift = 'class'
    elif shift_class == 'Front of House':
        class_foh_shift_tech_shift = 'front of house shift'
    elif shift_class == 'Tech':
        class_foh_shift_tech_shift = 'tech shift'

    message = f"BKLYN CLAY {shift_class} Coverage {date}\n\n"
    message += f"Hi there - This email is to confirm that {name1} will be covering {name2}'s {class_foh_shift_tech_shift} on {date} "
    message += f"from {start_time} to {end_time} at {location}.\n\n"
    message += "If the above contains any errors or is not what you agreed to, please reach out immediately so that we can revise the schedule.\n\n"
    message += "Best,\n"
    message += "The BKLYN CLAY team"

    messages.append(message)

CHANGES I MADE:

  1. I added the entirety of the if/elif portion.
  2. I added the two instances of the .strftime method (which I'm not positive I did correctly, but that alone wouldn't have messed up the elif portion).
  3. I added the .strip method just in case the problem was whitespace (it wasn't).

After you made the changes did you reload your webapp? The webapp on PythonAnywhere is a production version of your app so it doesnt watch for changes and reload automatically like the development server on your local machine might

I hadn't, and will do that now. I knew it had to be something like that. Thanks!

Well... now the webapp just isn't up and running anymore at all. I'm getting the "Something went wrong :-(" error.

Really frustrating. Why would this be? All I did was make the above changes and then reload the app.

Probably a code error. Is there anything in the webapp error logs?

It's giving me:

NameError: name 'df' is not defined

I don't know why that could possibly be. Here's every instance of "df" in the code:

1) df = pd.DataFrame(worksheet.get_all_records())

This was exactly the same in the old version, which worked.

2) for index, row in df.iterrows():

This is the beginning of the "for" statement from my original post. The line itself is the same as it was before. The "for" statement includes the changes I described up above, plus one more minor change (see below). I don't see why any of that would cause the problem.

3) print(df)

This is the same as it was before.

The one additional change I've made in the "for" statement since the original post is that underneath the line:

class_foh_shift_tech_shift = 'class'

I added, at the same level of indentation:

shift_class = 'Class'

The error "NameError: name 'df' is not defined" is telling whats wrong. The place where you're using df (either 2 or 3), df has yet been initialized

Right, but I don't get how that would be the case given the code I've described above. It seems like "df" HAS been initialized, so I don't understand why it's saying it's not. Can you help me figure that out?

As far as I can tell, the first place I used "df" initializes it. And like I said, every instance of "df" is exactly the same as it was previously, when the code worked just fine.

Well... I figured THAT part out: it was an indentation error in my views.py file, as opposed to my main script. But now I'm getting this:

APIError at / {'code': 429, 'message': "Quota exceeded for quota metric 'Write requests' and limit 'Write requests per minute per user' of service 'sheets.googleapis.com' for consumer 'project_number:320956537917'.", 'status': 'RESOURCE_EXHAUSTED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'RATE_LIMIT_EXCEEDED', 'domain': 'googleapis.com', 'metadata': {'quota_metric': 'sheets.googleapis.com/write_requests', 'quota_location': 'global', 'service': 'sheets.googleapis.com', 'consumer': 'projects/320956537917', 'quota_limit': 'WriteRequestsPerMinutePerUser', 'quota_limit_value': '60'}}, {'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Request a higher quota limit.', 'url': 'https://cloud.google.com/docs/quota#requesting_higher_quota'}]}]}

If I understand right, that means I've exceeded what Google's API will allow me to do? Which I guess would mean I exceeded it by repeatedly testing out the webapp to see if it was working? That seems... odd, and not consistent with my past usage. Unless it's a cumulative quota spread out over time?

Any idea what I can do about this? This seems strange for such a small little app.

For the df problem, I'd check that df is being initialized in the right scope as where it's being used.

For the google sheets problem, the error's telling you that you can send a maxiumum of 60 requests a minute to the google api. If you have a loop or some part of the code which sends a lot of requests then you may want to include a time.sleep(..) to space out the requests

Thanks, but I'm still confused about the Google Sheets problem. As far as I'm aware, my script is very simple and hasn't been used very often. More importantly, I'm not clear on what I need to do in order to get it up and running again. I'm unclear as to whether I have to play a waiting game, change something on the Google end, change something on the script end (unless it's time.sleep but I'm not at all clear that that's the issue given how low-maintenance my script already is), etc.

I would love any help resolving this! I just want to know what I need to do to get this simple little webapp working again.

I think it's pretty simple, you have a max 60 requests that you can make to the google api each minute. To fix the problem, make less than 60 requests

Thanks... but I don't understand what that means. It's not that simple to me, because I'm new at this. I've never worked with an API before.

I apologize if my lack of understanding is frustrating, but what I really need help with is figuring out more specifically what I need to do. I'm very confused about the nature of the problem itself, because I'm under the impression that my webapp does so little that there's no reason it would run into any sort of limits. Clearly I'm wrong, but I don't know why I'm wrong-- and more importantly, I don't know what I need to do to fix it.

If there's somewhere else I should be asking for help, please let me know and I can try there. Again, I apologize if my ignorance on this matter is frustrating, but... I need more beginner-level help. Being told to make less than 60 requests is over my head; I don't think I've been making very many requests, and I don't know how to even find that out, much less what to do about it.

Never mind-- was able to figure it out via ChatGPT. I used time.sleep like you said, but ChatGPT helped me contextualize how to do that in a way I was able to understand. Thanks!

Glad you found a solution!