Back

Getting started with the python SDK

  • 0
  • Accounts
  • Web
D5
15 Jun, 2023, 12:40

@srish What's the programming language you're using?

TL;DR
User is asking for help in getting started with the python SDK. They provide some code and mention that they are getting an error. Some confusion arises around the use of `client.setEndpoint()` and `account.create_session(email, password)`. A user suggests a code modification and the removal of a section of code. The updated code is provided. The user tries the updated code but still encounters the same error. They mention using Python.
Guille
15 Jun, 2023, 12:47

seems to be python

srish
15 Jun, 2023, 12:48

Yes python

srish
15 Jun, 2023, 12:50

See is there any error?

Guille
15 Jun, 2023, 12:54

You should do this:

TypeScript
result = users.create(ID.unique(), email=email, password=password, name=name)```
Guille
15 Jun, 2023, 12:55

import ID from appwrite SDK

Guille
15 Jun, 2023, 12:56

Remove this code:

TypeScript
# Generate a unique user_id using the email address and a unique identifier
userid = re.sub(r'[^a-zA-Z0-9.-]', '', email)  # Remove any special characters from the email
userid += '' + str(uuid.uuid4())
user_id = user_id[:36]
srish
15 Jun, 2023, 13:59

Here is the updated code

srish
15 Jun, 2023, 13:59

But still showing the same error

Nevus
15 Jun, 2023, 14:42

In the first image, remove your validation of user id. You are not supposed to validate user id yourself, appwrite does it on the backend and the returned error may be handled on the frontend. FYI, ID.unique() returns the string unique() and the backend generates an unique id internally

srish
15 Jun, 2023, 14:48

R u talking about user_id=ID.unique()?

srish
15 Jun, 2023, 14:48

This line👆

Drake
15 Jun, 2023, 14:53

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Guille
15 Jun, 2023, 15:07

Your code should be someting like this:

TypeScript
@app.route('/signup', methods=['GET', 'POST'])
def signup():
    error_message = None
    if request.method == 'POST':
        # Retrieve form data
        email = request.form['email']
        password = request.form['password']
        name = request.form['name'] if 'name' in request.form else ''

        try:
            result = users.create(ID.unique(), email=email, password=password, name=name)
            response = account.create_session(email, password)
            session_data = response.json()
            # Store the session data in the user's session
            session['userId'] = session_data['userId']
            session['email'] = email
            session['token'] = session_data['$id']
            # Redirect to the login page after successful signup
            return redirect(url_for('login'))
        except Exception as e:
            error_message = str(e)
            

    # Render the signup template
    return render_template('signup.html', error_message=error_message)
srish
15 Jun, 2023, 15:12

Okie let me try this one

srish
15 Jun, 2023, 15:53
srish
15 Jun, 2023, 16:16

Now how to solve this?

Drake
15 Jun, 2023, 16:25

You never called client.setEndpoint()

Drake
15 Jun, 2023, 16:28

what is account.create_session(email, password)?

did chatGPT generate this?? 😅

srish
15 Jun, 2023, 16:30

How to call client.setEndpoint()

Drake
15 Jun, 2023, 16:32

this might be helpful: https://appwrite.io/docs/getting-started-for-server

We have lots of docs so make sure to go through them thoroughly

Drake
15 Jun, 2023, 16:32

Getting started with the python SDK

srish
15 Jun, 2023, 16:37

I have set endpoint

srish
15 Jun, 2023, 16:40

But still it is showing error

Drake
15 Jun, 2023, 19:04

please share the exact error and your updated code

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more