Python Forum
Requests Session Overwriting and cookie jar
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Requests Session Overwriting and cookie jar
#1
Greetings,

I have two questions in regards to the code below, I will make note of them inside the code itself.

session = requests.Session()

# 1. I assign a session to the session variable but below, I re-assign a session.request to the session variable. Does this overwrite the initial session object? # should I define a new variable?
#2. I need to send and receive cookies or cookie jar on each request. See below.



BASE_URL = "https://www.homeadvisor.com/c.Flooring-Carpet.Dallas.TX.-12032.html"

def get_html(session, BASE_URL, PAGE):

    try:
        # How do I receive and send cookies with each request? I've researched it but the first time you enter a site, their aren't any cookies to be sent.

        PARAMS = {"startingIndex": PAGE}
        session = session.get(BASE_URL, headers=HEADERS, params=PARAMS)   # Is it considered good practice to re-assign this to the session variable?
    
       
    except requests.exceptions.RequestException as e:
        print("Failed to connect to host: " + BASE_URL)
        exit(
            "Check your internet connection. Then try to open the URL in a web browser. Program exiting."
        )
        exit("Could not establish connection to host. Terminating program!")

    return session
Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Paramiko mkdir command overwriting existing folder. How can i stop that? therenaydin 1 3,235 Aug-02-2020, 11:13 PM
Last Post: therenaydin
  Cookie and Session JohnnyCoffee 6 3,123 Apr-14-2020, 02:04 PM
Last Post: JohnnyCoffee
  Combining Dictionaries w/o overwriting MC2020 3 1,901 Apr-12-2020, 02:51 AM
Last Post: bowlofred
  Extract Httponly, Secure, domain and path from a cookie randeniyamohan 0 1,679 Jan-26-2020, 04:59 PM
Last Post: randeniyamohan
  AssertionError: View function mapping is overwriting an existing endpoint function Zhavi221 7 19,115 Apr-17-2019, 01:07 PM
Last Post: Zhavi221
  Save Cookie header value in var DavidFernandez 0 1,785 Aug-24-2018, 07:30 PM
Last Post: DavidFernandez
  Powershell Session translation to Python; Session code seems to not work Maverick494 1 3,622 Jun-26-2018, 05:16 PM
Last Post: Maverick494
  View function mapping is overwriting an existing endpoint function: index rarevesselt 12 19,519 Oct-22-2017, 12:34 AM
Last Post: rarevesselt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020