Connecting to Internet?

2024/11/20 10:21:35

I'm having issues with connecting to the Internet using python.

I am on a corporate network that uses a PAC file to set proxies. Now this would be fine if I could find and parse the PAC to get what I need but I cannot.

The oddity:

R can connect to the internet to download files through wininet and .External(C_download,...) so I know it is possible and when I do:

import ctypeswininet = ctypes.windll.wininet
flags = ctypes.wintypes.DWORD()
connected = wininet.InternetGetConnectedState(ctypes.byref(flags), None)
print(connected, hex(flags.value))

I get: 1 0x12 so I have a connection available but once I try to use other functions from within wininet I'm constantly met with error functions like:

AttributeError: function 'InternetCheckConnection' not found

and this goes for pretty much any other function of wininet, but this doesn't surprise me as the only named function in dir(wininet) is InternetGetConnectedState.

The wininet approach can clearly work, but I have no idea how to proceed with it [especially given that I only use Windows in work].

Answer

"ok, so poor wording - let's just change that to: open a connection to a web page and obtain its content using python "

Sounds like you actually need BeautifulSoup and Requests. Here's a quick example of them being used to explore a webpage

https://en.xdnf.cn/q/118427.html

Related Q&A

Angular App Not Working When Moving to Python Flask

Not sure what information to give so will do as much as I can. Currently have an Angular app sitting on IIS and using Classic ASP. All works fine. There is a dropdown which fetches some JSON that then …

How can I subtract tuples in a list?

Lets say I have a list with tuples in it.Something like this:listnum = [(18,12),(12,20)]Is there a way I can subtract what is in the tuples and make listnum into:listnum = [6,8]As you can see It takes …

Chart barh matplotlib - overlap bars

Im new user of matplotlib and I have a problem with chart barh: overlap bars. When plot the graph, the bars draws overlapped and I havent found the reason. In my opinion the problem is on re-size the …

Python django image upload is not working

Python Django image upload is not working when I am adding data and click on submit button not give a any response and also not upload any data in the database.models.py fisrst of all i add model file.…

Android bluetooth send message working first time only

I need to send string message from Raspberry PI to Android device. I am getting message first time only. After that it does not work at all. I am using PYTHON code in Raspberry PI. After first time, it…

Scraping data from href

I was trying to get the postcodes for DFS, for that i tried getting the href for each shop and then click on it, the next page has shop location from which i can get the postal code, but i am able to g…

Numpy - how to sort an array of value/key pairs in descending order

I was looking at the problem Fastest way to rank items with multiple values and weightings and came up with the following solution, but with two remaining issues:import numpy as np# set up values keys …

How to extract certain under specific condition in pandas? (Sentimental analysis)

The picture is what my dataframe looks like. I have user_name, movie_name and time column. I want to extract only rows that are first day of certain movie. For example, if movie as first date in the ti…

Flask app.run method does not work with WinPython 3.11.1 and next.js application: fetch failed

When using WinPython 3.10.5 I am able to debug my flask & next.js application using the flask debug mode (to enable hot reloads): app.run(debug=True, host=host, port=port)However, when using WinPyt…

Pythonic way to assign global administrator roles for Azure Active Directory

What specifically needs to be changed in the Python 3 code below in order to successfully assign the Global Administrator role for an Azure Active Directory Tenant to a given service principal? We tri…