First script : just trying to open a basic website

I tried this on a few different networks, and tried different URLS but I keep getting:
Failed to connect to the website.

Appreciate any assistance. Thank you
RD

import requests

# Disable proxy
proxies = {
    'http': None,
    'https': None
}

# URL
url = 'https://google.com.au'

# Form data to send
form_data = {
    'q': 'Whats my IP?'
}

try:
    # Send a POST request with the form data
    response = requests.post(url, data=form_data, proxies=proxies)

    # Check the response status code
    if response.status_code == 200:
        print('Connected to the website successfully!')
    else:
        print('Failed to connect to the website.')
except requests.exceptions.RequestException as e:
    print('An error occurred:', e)

Try printing out the response you did get. It isn’t 200, but the various
others have various meanings. Maybe it’s redirecting you to some other
URL.

champ, looks like a 405 error:
405 error when trying to response = requests.post(url, data=form_data, proxies=proxies)

Tried this as suggested by anaconda assistant and now I’m getting:

An error occurred: HTTPSConnectionPool(host=‘www.google.com.au’, port=443): Max retries exceeded with url: /search?q=Whats+my+IP%3F (Caused by ProxyError(‘Cannot connect to proxy.’, OSError(‘Tunnel connection failed: 403 Forbidden’)))

import requests

# Disable proxy
proxies = {
    'http': None,
    'https': None
}

# URL
url = 'https://google.com.au/search'

# Form data to send
params = {
    'q': 'Whats my IP?'
}

try:
    # Send a POST request with the form data
    response = requests.get(url, params=params, proxies=proxies)

    # Check the response status code
    print(response.status_code)
    
except requests.exceptions.RequestException as e:
    print('An error occurred:', e)

Hey Matt what are you trying to achieve? If its getting your IP address I don’t think if its a valid request to Google, coz this request involves JS rendering more so you aren’t locating any web elements. Use selenium so that you can locate the search field then send keys(your query) which is quite a hassle.
Nywy if its just to print a successful msg on your console then use the ‘insecure’ connection(http) to most URLs to make a succesful connection but not for google as it will automatically redirect you to a secure connection and eventually fail to connect lol.
But if you want to print your current IP easily which I think its your goal make a request to http://icanhazip.com instead of google… this usually has your IP as its body then grab the reponse and it print the text’s response. You can check this out custom proxy git clone and play around with it.

Thank you :slight_smile:

I was hoping to make testing suite for a website using Python where I navigate to the page, enter data into fields, submit etc. I just picked a random idea to enter into google as part of the original script.

I was hoping to learn python as I went doing this but sounds like I might be a simple case of wrong tool for the job. I will look into selenium again as I might have a bit more knowledge behind me now compared to when I first looked at it and cowered in the foetal position.

Thank you