Reputation: 110592
I would like to view the movie content from a different country on the Playstation store. However, the playstation store blocks the IP based on location of the request, so a movie in Canada cannot be viewed from the US:
https://store.playstation.com/#!/en-ca/movies/the-house/cid=UV0130-NPVA92773_CN-0000000000236063
Is there a way to do something like the following:
url = 'https://store.playstation.com/#!/en-ca/movies/the-house/cid=UV0130-NPVA92773_CN-0000000000236063'
r = requests.get(url, proxy_from = COUNTRY['CA']) # In pseudocode
Basically, so that you can specify a country and then send a request from an IP that would be recognized as coming from that country. How would this be done?
Upvotes: 5
Views: 4353
Reputation: 18743
If I understand correctly you are basically asking how to make a url request in python using a proxy?
If yes, you can do it like follows:
import urllib2
import urllib
import random
CAproxies = [{"http":"199.201.122.175:3128", "https":"199.201.122.175:3128"},{"http":"192.99.3.129:3128", "https":"192.99.3.129:3128"},{"http":"192.99.246.101:8118", "https":"192.99.246.101:8118"},{"http":"205.205.129.130:443", "https":"205.205.129.130:443"} ]
proxies = urllib2.ProxyHandler(random.choice(CAproxies))
url = 'https://store.playstation.com/#!/en-ca/movies/the-house/cid=UV0130-NPVA92773_CN-0000000000236063'
request = urllib2.Request(url)
request.add_header("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0")
request.add_header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
opener = urllib2.build_opener(proxies)
urllib2.install_opener(opener)
r = urllib2.urlopen(request, timeout=15)
html = r.read()
The headers are good if you want the service to think you are using a browser, they usually have defences against bots. You need to replace the proxy address with your own proxy, this is just an invented proxy for illustration purposes.
A list of Proxies can be found here for example: http://www.proxy-listen.de/Proxy/Proxyliste.html In case the proxy given above doesn't work. In case one of the proxies work better for your particular location (lets say the 2nd one works best for you, it might be a good idea to change the random choice of a proxy to only the second one. i.e.
random.choice(CAproxies) -> CAproxies[1]
CAproxies[3] works the best for me. The first 250 characters from the html:
>>> html[0:250]
'<!DOCTYPE html>\n\n<html class="ctry mobvportA rgba">\n <head>\n <meta http-equiv="x-ua-compatible" content="IE=edge" />\n <meta charset="utf-8"/>\n\n <link rel="dns-prefetch" href="//ajax.googleapis.com">\n <link rel="dns-prefetch" href="//ssl.'
Upvotes: 4
Reputation: 7468
Something you can do is just diagnose and try to figure out if that is possible at all.
First thing you can do is using a VPN
or any Proxy
simulate your location as coming from Canada. If that works, and you are able to load the required page, then most probably the location is determined from the request IP.
And actually from the viewpoint of the service, in your case the Playstation store, there is no other reliable piece of information to retrieve client's geo-location from.
So if this is the situation, the only reasonable solution for your problem would be to change your IP address somehow. But anyway, if you do that on your application side, there will be too many layers, e.g. routers, that will anyway expose your real location, as the final IP packet
that reaches the service, will contain the real real IP
.
Thus, it is nothing to do with your application or request client, you should rather think about what to put in front of it.
So if your question is:
How to achieve my goal on the application side?
...then the answer is: most probably no way :/
But if you ask:
How can I achieve my goal?
...then there are options:
proxy
or VPN
. You will certainly find a VPN service, that will provide access credentials (e.g. OpenVPN config
) per location, so you can load them programatically. That can be implemented on your application side.Upvotes: 0