0

I have a problem to login on twitch with selenium. After the bot has entered the credentials (I also tried to enter them manually) the error message appears: "Something went wrong. Please try again." And it won't let me in.

Any suggestions?

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

def start_twitch_viewer():

    PATH = r"./Local/twitch-stream-viewer/chromedriver"
    email = 'username@gmail.com'
    usr = 'Username'
    pswd = 'Password'


    chrome_options = webdriver.ChromeOptions()

    try:

        driver = webdriver.Chrome(PATH, options=chrome_options)
        driver.get("https://www.twitch.tv/ChannelName")
        driver.header_overrides = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"}

    except:
        return
    
    time.sleep(10)
    driver.find_element(By.CSS_SELECTOR, "div[class='Layout-sc-nxg1ff-0 csWXEI']").click()
    time.sleep(5)
    username=driver.find_element(By.CSS_SELECTOR, "input[id='login-username']")
    password=driver.find_element(By.CSS_SELECTOR, "input[id='password-input']")
    username.clear()
    password.clear()
    username.send_keys(usr)
    password.send_keys(pswd)
    time.sleep(5)
    driver.find_element(By.CSS_SELECTOR, "div[class='Layout-sc-nxg1ff-0 OZCSg']").click()
    

    time.sleep(1000)




if __name__ == "__main__":
    start_twitch_viewer()

EDIT: This is the file based on the suggestion given by @Lenta.


    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("user-data-dir=/Users/usr/Library/Application Support/Google/Chrome")
    chrome_options.add_argument("profile-directory=Profile 3")
    chrome_options.add_experimental_option("detach", True)
    
    try:

        driver = webdriver.Chrome(executable_path=PATH, options=chrome_options)
        driver.set_window_position(0, 0)
        driver.set_window_size(1440, 900)
        driver.get("https://www.twitch.tv/user")
        
    except:
        return

Piero
  • 404
  • 3
  • 7
  • 22

4 Answers4

1

To fix this issue "Something went wrong. Please try again." you can use your own chrome profile, but it's better to create a new one to work with selenium, since the main profile will load all installed extensions that may not work with selenium.

How to create a new profile you can see here: How to open a Chrome Profile through Python

To add your profile use the following code:

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=O:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("profile-directory=profile_directory_name")
service = Service(executable_path='path\to\your\chromedriver.exe')
driver = webdriver.Chrome(service=service, options=options)

If you get the error "selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir" you need to close your main browser as it blocks the browser launching from selenium

Or you can use a profile from another browser such as firefox or edge but for this you need to install the necessary webdriver geckodriver or edgedriver.

To add your profile from firefox:

options = webdriver.FirefoxOptions()
options.add_argument("-profile")
options.add_argument("O:\\Users\\Username\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\wfpwqtvd.default-release")
service = Service(executable_path='path\to\your\geckodriver.exe')
driver = webdriver.Firefox(service=service, options=options)

To add your profile from edge:

options = webdriver.EdgeOptions()
options.add_argument("user-data-dir=O:\\Users\\Username\\AppData\\Local\\Microsoft\\Edge\\User Data")
options.add_argument("profile-directory=profile_directory_name")
service = Service(executable_path='path\to\your\msedgedriver.exe')
driver = webdriver.Edge(service=service, options=options)
Brze
  • 525
  • 1
  • 5
  • 8
  • Hi @Lenta thanks for your reply. Unfortunately I'm not sure if it works because when I try it and click on the login button it crashes (I tried it manually and the problem persists) this only happens with the profile. Any suggestions? – Piero Oct 05 '22 at 17:34
  • Hi @Lenta . Unfortunately it dosen't work. The problem persist. – Piero Oct 05 '22 at 17:42
  • @Piero what error do you get when it crashes? – Brze Oct 06 '22 at 09:04
  • Forget it. It was just a typing error on the code regarding the login button. However the problem does not change and it always remains the words "Something went wrong. Please try again." – Piero Oct 06 '22 at 09:55
  • Will your new chrome profile connect for sure? Can you show your code? – Brze Oct 06 '22 at 09:59
  • Yep. when selenium start I can see my new google account it's running. I have add the code on the question. – Piero Oct 06 '22 at 12:46
  • Yes, that's right, it should work. I tested again and everything works fine, after filling in the login details, I get a window "verify login code". Try using gecodriver and firefox browser. How to connect a profile for FireFox I wrote in the answer. You can also try to log into the twitch account under this chrome profile from the browser, the data will be saved in the profile and then you will not need to log in using selenium – Brze Oct 06 '22 at 14:51
  • I have tested both the solution and work like a charm on Firefox, but it dosen't work on chrome. Any other suggestion? – Piero Oct 06 '22 at 19:15
  • Do you close chrome before running your script? – Brze Oct 07 '22 at 06:28
  • Yes I close chrome every time – Piero Oct 07 '22 at 07:10
  • 1
    I tested this script on linux and get the same error. I assume that this is related to the OS (linux, mac) since everything works on win 10. Then I can only recommend you to use firefox and gecodriver – Brze Oct 07 '22 at 11:17
  • you can start with incognito mode, it will work too. – Bahadır Öz Dec 03 '22 at 05:33
  • btw, just tested, if you start directly with incognito mode it doesn't work. but if you start without incognito and manually open incognito window it's working. how do they detect it? – Bahadır Öz Dec 03 '22 at 05:40
1

It looks like the www.twitch.tv website is using a Fastly security tool.

A quick DNS lookup shows that www.twitch.tv resolves to twitch.map.fastly.net.

They are most likely using the Signal Sciences product (https://www.signalsciences.com/about-us/news/fastly-to-acquire-signal-sciences/). I have encountered this on another website recently.

Typically rotating user agents and IP addresses (ideally using residential proxies) should do the trick. You want to load up the site with a "fresh" browser profile each time.

Jeff Rainer
  • 103
  • 1
  • 5
0

I tried that and saw the Something went wrong. notification displayed.
I'm quite sure that site is blocking automated tools like Selenium to prevent boots there.
Try using undetected Selenium.

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • 1
    Thanks @Prophet for your help. Could you tell me where I can find more information regarding undetected Selenium – Piero Oct 02 '22 at 17:55
  • I'm not familiar with it. Otherwise I would give you more information. – Prophet Oct 02 '22 at 18:15
0

I believe certain Twitch users have been having issues logging in these past few days so it may be related. I had the "Something went wrong" error on Brave when trying to login but it worked on Edge. There's this article reporting the issue from a couple of days ago:

https://piunikaweb.com/2022/09/30/twitch-users-unable-to-login-getting-something-went-wrong-error/

  • I thank you @RampantLion. Unfortunately, however, I have already tried with the recommended fixes but the problem persists. This problem occurs only from the window opened by chromedrivers while it does not give any problem from a normal Chrome window or from Safari. – Piero Oct 02 '22 at 22:39