Error with f-strings and URLs

Summary

I recently deployed my code that was written in version 1.12.2 not knowing that the current version is 1.20.0

Steps to reproduce

Code snippet:

    with l2:
        st.header("Create Account")
        pas = st.text_input("Password (Required)")
        em = st.text_input("Email (Optional)")
        if pas:
            if len(pas) >= 8:
                siup = st.button("Sign Up", key="signup")
                em = None if not em else em
                if siup:
                    with st.spinner("Creating account..."):
                        uname = requests.get("https://apis.kahoot.it")
                        usa = requests.post(
                            f"https://school.deta.dev/data/create/user?username={uname.json()['name']}&password={pas}&email={em}"
                        )
                        st.success("Acount created!")
                        with st.container():
                            st.write("__Your Login Details__")
                            st.write(f"`Username:` {usa.json()['username'][0]}")
                            if em != None:
                                st.write(f"`Email:` {usa.json()['email'][0]}")
                            st.write(f"`Password:` {usa.json()['password'][0]}")
            else:
                st.error("Password to short, please use at least 8 characters!")

Expected behavior:

A new account should be created

Actual behavior:

I got this error: https://codebin-1-s6167056.deta.app/bin/c4d2d940 After updating to the latest version I went back to testing on local and I got this error: https://codebin-1-s6167056.deta.app/bin/957efbd0

Debug info

  • Streamlit version: 1.20.0
  • Python version: 3.9.13
  • Using Conda
  • OS version: Mac
  • Browser version: Arc (Chromium based)

Requirements file

streamlit_option_menu
streamlit

Links

In the code of your repo, try changing

BASE_URL = "https://school.deta.dev/"

to

BASE_URL = "https://school.deta.dev"

Otherwise, the f-string that you are building later (i.e. usa) ends up with two consecutive //, which is probably what triggers an 404 error response from that API.

usa = requests.post(f"{BASE_URL}/data/create/user?username={uname.json()['name']}&password={pas}&email={em}")

A sorry, that is the outdated code, I forgot to push the changes I had on my local machine, here is the latest code

Updated · SlumberDemon/SchoolPlace@33c2c2c · GitHub

Latest version shows no errors on my end.

Yes, it seems only the local version is struggling but the online version is fine, thanks for the help, I think this was a bit of a dumb mistake on my end somewhere!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.