Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG ? Aiohttp won't keep the same session between requests #3643

Closed
SneakerSociety opened this issue Mar 7, 2019 · 4 comments
Closed

BUG ? Aiohttp won't keep the same session between requests #3643

SneakerSociety opened this issue Mar 7, 2019 · 4 comments

Comments

@SneakerSociety
Copy link

Long story short

I've been trying to write a code that has two requests. First is a post and second is a get request on the redirect from the post request. I'm getting a 404 error on the get request. It seems like cookies aren't saving between the two requests or two separate sessions are created.

Expected behaviour

I expected two requests to be in the same session.

Actual behaviour

I was trying to make a script that would sign up for an account on cncpts.com. When you try and sign up more than once on an IP it redirects you to a link cncpts.com/challenge which is where you solve a captcha. Anyways, if you try to go to /challenge without making an account first you get a 404 error. So I have two requests, first a post request to fill out the sign up information and then a get request on /challenge so I can parse it for a token I need. I was assuming that with aiohttp sessions are saved like requests but whenever I run the script I get a 404 error as if the requests are being sent with different cookies/sessions.

I've been asking around and no one seems to know. You guys are my last hope. I was told it might be a bug or something, not 100% sure.

Your environment

Current aiohttp version, Windows
Client

Steps to reproduce

import random
import names
import discord
import asyncio
from bs4 import BeautifulSoup

async def generator():
    session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False))
    first = names.get_first_name(gender= 'male')
    last = names.get_last_name()
    catchall = '@gmail.com'
    random_number = random.randint(1,10000)
    global email
    email = last+f'{random_number}'+catchall
    password = 'Solefood9473'

    headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Referer': 'https://cncpts.com/account/login',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
    }

    info = {
    'form_type': 'create_customer',
    'utf8': '✓',
    'customer[first_name]': first,
    'customer[last_name]': last,
    'customer[email]': email,
    'customer[password]': password
    }

    async with session.post('https://cncpts.com/account', data=info, headers=headers) as resp:
        if str(resp.url) == 'https://cncpts.com/':
            print('Successfully signed up!')
            print(f'{email}:{password}')

        else:
            print('Captcha needed, submitting now...')
            async with session.get('https://cncpts.com/challenge') as resp:
                url = await resp.text()
                print(url)

                soup = BeautifulSoup(url, 'html.parser')
                auth_val = soup.findAll("input", {"name": "authenticity_token"})
                auth_final = auth_val[0]["value"]
                print(auth_final)
                
        await session.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(generator())
@SneakerSociety SneakerSociety changed the title Aiohttp won't keep the same session between requests BUG ? Aiohttp won't keep the same session between requests Mar 12, 2019
@ghost
Copy link

ghost commented Mar 26, 2019

Have similar errors when I work with some sites.

@odysseusmax
Copy link

I too experience this issue. In requests made with same session, cookies are lost, and the requests are treated as separate new requests. Hope will be fixed soon

@blueyed
Copy link
Contributor

blueyed commented May 2, 2019

This needs more details, e.g. cookies being lost.
It might be due to cookies not getting parsed/recognized in the first place (see #2502 (comment)).

@asvetlov
Copy link
Member

asvetlov commented Oct 3, 2019

Close, people don't provide required info

@asvetlov asvetlov closed this as completed Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants