How to Use Mobile Proxies with Python Requests

The requests library takes a proxies dictionary on every call or on a Session. The code below sends a request through your line and prints the address that the server sees. Replace the password placeholder with your own.

What do I need before I start?

Hostgw.mobileproxy.live
HTTP and HTTPS port9000
SOCKS5 port9100
Usernamemp4x9q2.mobile.us.sid-a1b2.rot-10
PasswordYOUR_PASSWORD (your own line password)
  • Python 3.9 or newer
  • The requests package (pip install requests)
  • Your username and password in your account under My lines. The username above is an example, and each part is explained in the username reference.

How do I set it up?

  1. Install the library with pip install requests. For SOCKS5, install pip install "requests[socks]".
  2. Create a file named check_ip.py and paste the code for HTTP below.
  3. Replace YOUR_PASSWORD with your line password. Keep the username as shown in your account.
  4. Run python check_ip.py. The printed JSON should show your line address and country.
  5. For several requests, use a Session so the connection and the proxy setting are reused.
  6. Add a timeout to every call, and handle errors with a retry and a short pause.

What does the code look like?

HTTP proxy (check_ip.py)
import requests

proxy = "http://mp4x9q2.mobile.us.sid-a1b2.rot-10:YOUR_PASSWORD@gw.mobileproxy.live:9000"
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://ipinfo.io/json", proxies=proxies, timeout=30)
print(r.json())
SOCKS5 proxy with a Session
import requests

proxy = "socks5h://mp4x9q2.mobile.us.sid-a1b2.rot-10:YOUR_PASSWORD@gw.mobileproxy.live:9100"

with requests.Session() as s:
    s.proxies = {"http": proxy, "https": proxy}
    r = s.get("https://ipinfo.io/json", timeout=30)
    print(r.json())

How do I check my IP?

The script prints the JSON from https://ipinfo.io/json. The ip and country fields must be those of your line. Run it once without proxies to see your own address for comparison.

https://ipinfo.io/json

On a mobile line you can ask for a fresh address at any time with your change-IP link, for example https://gw.mobileproxy.live/rotate/k7Qm2xV9. The real link for each line is in your account.

What if it does not work?

ProxyError or 407 Proxy Authentication Required.

The username or password is wrong. Check the dots in the username, and encode special characters in the password with urllib.parse.quote.

Missing dependencies for SOCKS support.

Install requests[socks] and use socks5h:// so the proxy also resolves hostnames.

Requests time out.

Raise the timeout, or ask for a new IP with the change IP link, since a mobile network can be slow at busy hours.

Frequently asked questions

HTTP or SOCKS5 in Python?

HTTP on the HTTP port is simpler and works for most sites. SOCKS5 needs the extra socks package.

How do I keep one IP for a series of calls?

Add a session id to the username, such as the sid part, and use the same username for all the calls within the timer.

Can I use it with aiohttp or httpx?

Yes. Both accept a proxy URL in the same host, port, username and password form.

Related guides

Need a line to connect?

Create an account, top up your balance and your first line is ready to use with Python requests.

Create account