14

I'm trying to add the ppa repository (as a root) with the following command:

export HTTP_PROXY="http://[email protected]:[email protected]:8080"
add-apt-repository ppa:nilarimogard/webupd8


Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 125, in <module>
    ppa_info = get_ppa_info_from_lp(user, ppa_name)
  File "/usr/lib/python2.7/dist-packages/softwareproperties/ppa.py", line 84, in get_ppa_info_from_lp
    curl.perform()
pycurl.error: (56, 'Received HTTP code 407 from proxy after CONNECT')

Unfortunately it doesn't work. Looks like curl is connecting to the proxy, but the proxy says that Authentication is Required. I've tried with .curlrc, http_proxy env instead, but it doesn't work.

strace -e network,write -s1000 add-apt-repository ppa:nilarimogard/webupd8
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 4
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 4
connect(4, {sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("165.x.x.232")}, 16) = -1 EINPROGRESS (Operation now in progress)
getsockopt(4, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
getpeername(4, {sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("165.x.x.232")}, [16]) = 0
getsockname(4, {sa_family=AF_INET, sin_port=htons(46025), sin_addr=inet_addr("161.20.75.220")}, [16]) = 0
sendto(4, "CONNECT launchpad.net:443 HTTP/1.1\r\nHost: launchpad.net:443\r\nUser-Agent: PycURL/7.22.0\r\nProxy-Connection: Keep-Alive\r\nAccept: application/json\r\n\r\n", 146, MSG_NOSIGNAL, NULL, 0) = 146
recvfrom(4, "HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: BASIC realm=\"proxy\"\r\nCache-Control: no-cache\r\nPragma: no-cache\r\nContent-Type: text/html; charset=utf-8\r\nProxy-Connection: close\r\nSet-Cookie: BCSI-CS-91b9906520151dad=2; Path=/\r\nConnection: close\

Maybe it's because there is @ sign in the username? Wget works with proxy fine.

Related: How do I add a repository from behind a proxy?

Environment

Ubuntu 12.04

curl 7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3

curl Features: GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP

UPDATE

When added credentials into .curlrc

cat ~/.curlrc 
proxy = 165.x.x.232:8080
proxy-user = [email protected]:mypass0

It seems to work for the plain curl.

curl www.google.com | head

* Proxy auth using Basic with user '[email protected]'
GET HTTP://www.google.com HTTP/1.1
Proxy-Authorization: Basic cmFmYWwud2llY3pvcmVrQHVi...3R0RDA=
HTTP/1.1 302 Found

Also HTTPS:

curl -v https://www.google.com | head
* Establish HTTP proxy tunnel to www.google.com:443
* Proxy auth using Basic with user '[email protected]'
> CONNECT www.google.com:443 HTTP/1.1
> Host: www.google.com:443
> Proxy-Authorization: Basic cmFmYWwud2llY3pvcmVrQHVi...3R0RDA=
    > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1     zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Proxy-Connection: Keep-Alive
< HTTP/1.1 200 Connection established
* Proxy replied OK to CONNECT request
* successfully set certificate verify locations

But still doesn't work when adding ppa certificate.

pycurl.error: (56, 'Received HTTP code 407 from proxy after CONNECT')

CURL HEADERS

Headers sent:

CONNECT launchpad.net:443 HTTP/1.1
Host: launchpad.net:443
Proxy-Authorization: Basic cGVvcGxlcmVhbGx5c2hvdWxkQHNhbml0aXplcG9zdHM=
User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Proxy-Connection: Keep-Alive

Reply:

HTTP/1.1 200 Connection established

PyCURL HEADERS

Headers sent:

CONNECT launchpad.net:443 HTTP/1.1
Host: launchpad.net:443
User-Agent: PycURL/7.22.0
Proxy-Connection: Keep-Alive
Accept: application/json

Reply:

HTTP/1.1 407 Proxy Authentication Required
Proxy-Authenticate: BASIC realm="proxy"

It seems that PyCURL doesn't re-send any Authorization when requested.

6
  • Thanks, I've tried but this doesn't help. To make sure that this is not the case, I've included my credentials in .curlrc (without escaping @ seems to work for standard curl command), but not for pycurl. See the updated section.
    – kenorb
    Nov 5, 2012 at 13:22
  • Thanks, I thought I missed something. I've reported the bug here: bugs.launchpad.net/ubuntu/+source/apt/+bug/1075180
    – kenorb
    Nov 5, 2012 at 15:00
  • Have you also set https_proxy? See bug bugs.launchpad.net/ubuntu/+source/software-properties/+bug/…
    – popey
    Dec 29, 2012 at 19:08
  • Maybe it is a problem related to sessions and environment vars. You could try to export http_proxy and https_proxy in /etc/profile, then reboot the machine (if possible) and try it again.
    – jap1968
    Dec 30, 2012 at 21:50
  • Related to what jap1968 is saying above me, I'd made sure that both http_proxy and HTTP_PROXY are set (and https_proxy and HTTPS_PROXY). Thanks to Linux's case-sensitivity, those are actually two different variables - and, best of all, not all programs will use one or the other. Granted, it sounds more like an issue with how the username/password combination is being sent (because of '@'), but it's worth a shot anyway. Jan 22, 2013 at 20:08

3 Answers 3

11

Workaround if apt-get still works behind the proxy

  • add sources manually to /etc/apt/sources.list
  • add gpg key

Adding sources manually

I think on launchpad.net every ppa still contains a small description how to add sources manually. The launchpad site for your mentioned ppa ppa:nilarimogard/webupd8 is https://launchpad.net/~nilarimogard/+archive/webupd8. If you scroll down you see an expandable label Technical details about this PPA. If you expand it you find the description how to add sources manually. Add the following lines to mentioned /etc/apt/sources.list

deb http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu quantal main 
deb-src http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu quantal main 

Of course you have to adjust quantal to whatever version you are currently using.

Adding the Signing Key

The description also contains a signing key. This is important, so that your system can always verify that you actually access a trustworthy ppa-address. In case of your ppa that is 1024R/4C9D234C(can also be found under Technical details about this PPA), where the number behind the slash is important. You can add the fingerprint via the apt-key program. Typically you would perform the following command

 sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 4C9D234C

Adding if apt-key doesn't work through proxy

Since you already had problems with the add-apt-repository program this might not work either. So instead you can download and add the 1024 Bit key manually. If wget works you can do that in one step.

wget "http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x531EE72F4C9D234C" -O out && sudo apt-key add out && rm out

Otherwise safe "http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x531EE72F4C9D234C" in e.g. /path/key and use sudo apt-key add /path/key to add it.

Close with the usual

Afterwards you have to update the repository information apt-get update and then you should be able to download the packages.

Resources

My personal favorite on how to use the packaging mechanism (sadly in German): http://wiki.ubuntuusers.de/Paketquellen_freischalten/PPA

The launchpad version also mentions all the important points: https://help.launchpad.net/Packaging/PPA/InstallingSoftware

Since it is untypical to use apt-key in the described way I only found the information in the man pages, man apt-key.

Related answer that pretty much describes the standard way to install ppa's manually: https://askubuntu.com/a/38029/128349

3
  • @kenorb don't know if you get a notification if I edit my post, so: ping: "possible workaround"
    – LeoR
    Feb 6, 2013 at 19:21
  • If your problem is that the port 11371 is blocked in your corporate firewall, you can now use the port 80 instead: "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4C9D234C" Feb 24, 2014 at 9:51
  • This walk-through covers most things. Also consider copying your GPG format key into /etc/apt/trusted.gpg.d as well as or instead of /usr/share/keyrings: digitalocean.com/community/tutorials/…
    – NeilG
    Jun 20, 2023 at 11:26
8

Actually it seems to be much easier than the answer posted previously. You just need "sudo" to know that you are behind a proxy and it will work effortlessly. To do this, you need to export your proxy for http and https the way you usually do:

export http_proxy=http://username:password@host:port/
export https_proxy=https://username:password@host:port/

and then add Defaults env_keep="https_proxy" to then end of /etc/sudoers file. After this you should be able to add the ppa using the command:

sudo add-apt-repository ppa:the_ppa_you_want_to_add

or use

sudo -E add-apt-repository ppa:the_ppa_you_want_to_add

if you don't want to modify /etc/sudoers file. The -E option exports environment variables to the sudo user.

I have given a detailed description about this here on my blog.

1

Make sure apt proxy is set like below

sudo vi /etc/apt/apt.conf

add following proxy settings and save the file

Acquire::http::proxy "http ://proxy.company.com:port/";
Acquire::https::proxy "https ://proxy.company.com:port/";
Acquire::ftp::proxy "ftp://proxy.company.com:port/";

in addition export following in Terminal before you run the command

export http_proxy=http ://proxy.company.com:port/
export https_proxy=https ://proxy.company.com:port/

This should work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .