How to connect my VPN with the python requests? - python

My IP is not changing after connecting to the VPN(NordVPN). Here's my code:
How can I fix this? I am noob in python please help by listing the step by step guide.
import requests
res=requests.get("https://httpbin.org/ip")
print(res.text)

I can't comment on this post so I'll just tell you that you should format code by surrounding it with backticks (this character: ` ). Also, please separate each line. Please update your post.
As for your question, please do understand that Python code is not necessary to check your IP address. Simply going to that web address in your browser should show you your IP. Moreover, if your IP address is not changing after enabling a VPN, your VPN is at fault, not Python. When I use a VPN and go to that address in the browser, it does work.
Finally, I suspect that you are using a NordVPN browser extension, not a system-wide VPN. In that case, Python is not actually going through your browser to access the web address. It is directly requesting the information from the webpage. If you install system-wide, it should work.

Related

Access Denied 403 when webscraping; What to do?

I was testing a scraping algorithm that I had built. I made a request to https://www2.hm.com/fi_fi/miesten.html but misspecified the user-agent information. It seems that this triggered an immediate ban (not sure) Scraping their site should be fine - their robots.txt says: User-agent: *
Disallow: )
Example of making a request to HM and the subsequent server response
I erased the user agent and proxy information due to privacy concerns. However, they are nothing out of the ordinary.
I receive the following as response:
"b'\nAccess Denied\n\n\n \nYou don't have permission to access "http://www2.hm.com/fi_fi/miesten.html" on this server.\nReference #18.2796ef50.1625728417.f9aab80\n\n\n'"
So my question is: is there anything that I can do to lift this ban? Can i connect someone from their end and ask to lift it? If so, where can this information usually be found.
Although this question concern this site in particular, this is a much broader question. In the case of a ban, can the user try to connect someone from the server? I thought about contacting customer support, but I heavily suspect they they cannot help with this issue, and won't even understand what it is about.
I have googled this issue, but not found anything of help. They usually advise to clear cache, memory etc. This is not the problem here. I can access the site via Chrome or other browsers, but when using requests via python, this problem appears.
Pretty sure you need to use a Javascript scraping bot, you can try with this tool: https://docs.python-requests.org/projects/requests-html/en/latest/
And to get contact informations about the owner of a website you can use the unix whois command:
whois hm.com

Page still get my IP although using Tor and Privoxy

I configured Tor browser and privoxy using https://jarroba.com/anonymous-scraping-by-tor-network/. When I checked my IP with http://icanhazip.com/, my IP addresses are changed; it works. But, when I tried to scrape desired website, I got:
You are attempting to access "website" using an anonymous private/proxy network. Please disable that and try accessing the site again.
Tor hides your IP address, but it does not hide the fact that you are using Tor, since Tor exit relays are public knowledge. For example, xmyip.com will tell you whether or not your IP is a Tor IP.
Given the error you received, it looks like that website blocks Tor users, which is a fairly common practice. See Tor users being actively blocked on some websites for more details.

Python URL Request under corporate proxy

I'm writing this application where the user can perform a web search to obtain some information from a particular website.
Everything works well except when I'm connected to the Internet via Proxy (it's a corporate proxy).
The thing is, it works sometimes.
By sometimes I mean that if it stops working, all I have to do is to use any web browser (Chrome, IE, etc.) to surf the internet and then python's requests start working as before.
The error I get is:
OSError('Tunnel connection failed: 407 Proxy Authentication Required',)
My guess is that some sort of credentials are validated and the proxy tunnel is up again.
I tried with the proxies handlers but it remains the same.
My doubts are:
How do I know if the proxy need authentication, and if so, how to do it without hardcoding the username and password since this application will be used by others?
Is there a way to use the Windows default proxy configuration so it will work like the browsers do?
What do you think that happens when I surf the internet and then the python requests start working again?
I tried with requests and urllib.request
Any help is appreciated.
Thank you!
Check if there is any proxy setting in chrome

Python urllib2: Getting blocked from a website?

I had been using urllib2 to parse data from html webpages. It was working perfectly for some time and stopped working permanently from one website.
Not only did the script stop working, but I was no longer able to access the website at all, from any browser. In fact, the only way I could reach the website was from a proxy, leading me to believe that requests from my computer were blocked.
Is this possible? Has this happened to anyone else? If that is the case, is there anyway to get unblocked?
It is indeed possible, maybe the sysadmin noticed that your IP was making way too many requests and decided to block it.
It could also be that the server has a limit of requests that you exceeded.
If you don't have a static IP, a restart of your router should reset your IP, making the ban useless.

How gmail come to know that if user is trying to access it from a browser or from other application?

I've made one program in Python using Web.py to access my gmail account. It gave me following error in beginning "Please log in via your web browser and then try again." Then I went to gmail security settings and enable it for accessing gmail from less secure apps. It started working fine from the program I've developed.
( Security Setting link: https://www.google.com/settings/security/lesssecureapps)
My question is how Gmail comes to know that from where I am trying to access it? Also, if you can share similar scenarios with me where you have to access something via web browser only?
Thanks in advance.
when you access gmail,maybe the http protocol is used,in http protocol header,User-Agent represent our browse and operation system information.Hope this helpful
Is the gmail account a normal account or your own domain? If its ur domain then you need to login and change the outbound relay section in settings.
unlock captcha will help to fix this problem
Another way simple way is if you go to the email after trying to access without browser a yellow notification will tell you that something tried to access your account.Follow steps and you may have whay you want.
Hope it helps!!

Categories

Resources