jmcarp / robobrowser

BSD 3-Clause "New" or "Revised" License
3.7k stars 337 forks source link

browser cookies dont get changed #78

Open ilovefood2 opened 7 years ago

ilovefood2 commented 7 years ago

I have a website that requires change of cookies (a post request to server and server replies with headers to set cookies )

here is response headers that supposed to be from chrome browser

HTTP/1.1 200 OK Cache-Control: no-cache, no-store, must-revalidate Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 user: 8888 lg: 2673 x-frame-options: SAMEORIGIN x-download-options: noopen Set-Cookie: BrandingUserLocationGroupID=ic4DUh/NXVp8VOKAtyDgbA==; expires=Fri, 01-Sep-2017 17:01:16 GMT; path=/; secure; HttpOnly Set-Cookie: .AUTH=A69C1A5EE8A5F3626385F35DA1B104EE7DFF5E5AF549DDB02EE8ED53931A0585C0FBB8299E3FC7B428A982B9826EF68390E659F4A74DCE00E195601F400D6E69F53907DADED4194F32DD08A72BA212DCCD0D23AB7C5BD56171E6C55EF1BE90849E9C81B2DAE23B05CA6E361326F44604; expires=Thu, 03-Aug-2017 17:01:17 GMT; path=/; secure; HttpOnly Server: Unknown X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Strict-Transport-Security: max-age=31536000;includeSubDomains Date: Wed, 02 Aug 2017 17:01:17 GMT Content-Length: 335

here is my post request

browser.session.headers['X-Requested-With']='XMLHttpRequest' browser.open('https://example.com/test/Users/set-role?id='+role_id+'&__RequestVerificationToken='+token,method='POST') print browser.response.content

this gives me error response as following

{"RedirectUrl":null,"IsSuccess":false,"Message":"Save Failed","CustomMessage":null,"Errors":[{"Key":"","Value":["An error has occurred. This error has automatically been saved for further analysis. Please contact technical support."]}],"Messages":{},"HasView":false,"ViewHtml":null,"ViewUrl":null,"IsValidationException":false,"IsValidationWarning":false,"ReloadPage":false,"IsSessionExpired":false,"Script":null,"NextWizardUrl":null,"PreviousWizardUrl":null,"ShowDialog":false}

anyone knows how to fix it?

thanks

ljluestc commented 8 months ago
from robobrowser import RoboBrowser

# Create a RoboBrowser instance
browser = RoboBrowser()

# Open the URL
url = 'https://example.com/test/Users/set-role?id=' + role_id + '&__RequestVerificationToken=' + token
browser.open(url)

# Modify the browser's cookies dictionary with the desired values
browser.session.cookies['BrandingUserLocationGroupID'] = 'new_value_for_BrandingUserLocationGroupID'
browser.session.cookies['.AUTH'] = 'new_value_for_AUTH'

# Perform the POST request again (or your desired action)
browser.open(url, method='POST')

# Print the response content
print(browser.response.content)