Linux http_proxy: escape @ character
to use services like wget on linux from behind a proxy server that requires username-password authentication
requires setting up an environment variable for the shell
usually it suffices to do this:
shashanksingh@nsl-31:~$http_proxy=http://username:password@proxyserver:80/
the placeholders having obvious meanings. A problem however arises if the password has an ‘@’ character inside it. This @, being a delimiter will mess things up, e.g., if the password were my@pass, the url will become
http://username:my@pass@proxyserver:80/
wget will then parse it and treat the first @ as if it were the delimiter to mark the end of the password and the beginning of the proxy address. As a result it will assume:
user: username pass: my proxy host: pass@proxyserver:80
and you will get an error like this
Resolving pass@proxyserver... failed: Name or service not known.
One possible solution that comes to mind is to escape the @. This somehow does not work (for wget at least). So
shashanksingh@nsl-31:~$http_proxy=http://username:\@password@proxyserver:80/
gives the same error (I wonder if I am guessing the escape character right, if you know why it’s not working please post in comments 🙂 )
A work-around is to create a .wgetrc file. wget loads this file when run (you can find more details here).
A file like this works fine for me
http_proxy=proxyserver:80 proxy_user=username proxy_passwd=my@pass
Place the .wgetrc file in your home directory ($HOME) or other possible locations as mentioned in the link above.
UPDATE: while escaping does not seem to work for wget, exporting a http_proxy in .bashrc seem to handle escaping using ‘\’. So if your password is @agrambagram, adding a line at the end of ~/.bashrc works
export http_proxy=http://username:\@agrambagram@proxyserver:80
Use URL encoding to specify special characters. e.g. encode @ as %40.
Example: export HTTP_PROXY=”http://raju:raju%401234@myproxy.com:80″
Username: raju
Password: raju@1234