push to github with https

1,608 views
Skip to first unread message

Dominik Ruf

unread,
Dec 23, 2011, 7:39:31 AM12/23/11
to hg-...@googlegroups.com
Hi,

I am behind a firewall which makes it difficult to clone with ssh (maybe even impossible) so I use the https URL.
I can clone the repositories but I am not able to push my changesets back to github.
I always get "abort: HTTP Error 401: Authorization Required"

Although I have set

[auth]
github.prefix = git+https://github.com
github.username = domruf
github.password = <mypassword>

What am I doing wrong? 

cheers
Dominik

Augie Fackler

unread,
Dec 23, 2011, 10:46:58 AM12/23/11
to hg-...@googlegroups.com

No idea. Maybe dulwich is doing the authn dance incorrectly? What
version of dulwich do you have installed?

>
> cheers
> Dominik
>
> --
> You received this message because you are subscribed to the Google
> Groups "hg-git" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hg-git/-/i5b_FtT0dPQJ.
> To post to this group, send email to hg-...@googlegroups.com.
> To unsubscribe from this group, send email to
> hg-git+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hg-git?hl=en.

Jelmer Vernooij

unread,
Dec 26, 2011, 6:23:13 PM12/26/11
to hg-...@googlegroups.com
Am 23/12/11 16:46, schrieb Augie Fackler:

> On 12/23/2011 6:39 AM, Dominik Ruf wrote:
>> Hi,
>>
>> I am behind a firewall which makes it difficult to clone with ssh (maybe
>> even impossible) so I use the https URL.
>> I can clone the repositories but I am not able to push my changesets
>> back to github.
>> I always get "abort: HTTP Error 401: Authorization Required"
>>
>> Although I have set
>>
>> [auth]
>> github.prefix = git+https://github.com
>> github.username = domruf
>> github.password = <mypassword>
>>
>> What am I doing wrong?
>
> No idea. Maybe dulwich is doing the authn dance incorrectly? What
> version of dulwich do you have installed?
>
Dulwich simply calls out to urllib2 to handle all of the authentication
stuff. It expects the base URL that is passed in to contain the
credentials, or for the caller to override _perform if it has a custom
way to do HTTP requests. As far as I can tell hg-git does neither, so
the credentials never end up in the HTTP layer.

I don't have much experience passing the credentials in the URL though -
bzr-git overrides HttpGitClient._perform (we want different backends to
share a single HTTP transport, so they don't set up their own
connections). I don't see why passing credentials in the URL wouldn't
work - but if it doesn't, I'd be interested to hear about it.

Cheers,

Jelmer

Dominik Ruf

unread,
Dec 27, 2011, 4:15:54 AM12/27/11
to hg-...@googlegroups.com
Hi Jelmer,

if I understand you correctly the following should work.

but I get "abort: HTTP Error 401: Authorization Required"
(I put whitespaces before and after the @. Otherwise google groups would hide it because it looks like a email address)

and with
hg push git+https://domruf:<mypassword>@github.com/domruf/...
I get httplib.InvalidURL: nonnumeric port: '<mypassword>@github.com'


Dominik Ruf

unread,
Dec 27, 2011, 8:47:33 AM12/27/11
to hg-...@googlegroups.com
FYI

I made a small hack to work around this problem.
As Jelmer suggested I override _perform.
I use the credentials stored in the configuration file.
Maybe this is of some help for others.

diff -r 32afa497834d hggit/git_handler.py
--- a/hggit/git_handler.py Fri Nov 11 16:25:56 2011 +0100
+++ b/hggit/git_handler.py Tue Dec 27 14:46:33 2011 +0100
@@ -1104,7 +1104,20 @@
             if not httpclient:
                 raise RepoError('git via HTTP requires dulwich 0.8.1 or later')
             else:
+                ui = self.ui
+                def _perform(self, req):
+                    import base64, urllib2
+                    prefix = [item[0].split('.')[0] for item in ui.configitems('auth') if item[0].endswith('prefix') and uri.startswith(item[1])][0]
+                    
+                    username = ui.config('auth', '%s.username' % prefix)
+                    password = ui.config('auth', '%s.password' % prefix)
+                    base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
+                    req.add_header("Authorization", "Basic %s" % base64string)
+                    return urllib2.urlopen(req)
+
+                client.HttpGitClient._perform = _perform
                 return client.HttpGitClient(uri, thin_packs=False), uri
 
         # if its not git or git+ssh, try a local url..
         return client.SubprocessGitClient(thin_packs=False), uri
+

Jelmer Vernooij

unread,
Dec 27, 2011, 9:24:34 AM12/27/11
to hg-...@googlegroups.com
Am 27/12/11 10:15, schrieb Dominik Ruf:
I expected this would work, but apparently urllib2 doesn't support
passing credentials in the URL.

I've filed a bug about this in Dulwich:
https://bugs.launchpad.net/dulwich/+bug/909037

Cheers,

Jelmer

Dennis Schridde

unread,
May 31, 2012, 11:37:54 AM5/31/12
to hg-...@googlegroups.com
Am Dienstag, 27. Dezember 2011 14:47:33 UTC+1 schrieb Dominik Ruf:
I made a small hack to work around this problem.
As Jelmer suggested I override _perform.
I use the credentials stored in the configuration file.
Maybe this is of some help for others.
Looks great! Has this gone into upstream code already?

ndesl...@live.fr

unread,
Apr 12, 2014, 12:47:48 PM4/12/14
to hg-...@googlegroups.com
In case it's useful to someone else, using the code from Dominik in the last version of hggit, I had to change my .hgrc file to:

[auth]
github.prefix = https://github.com
github.username = nico
github.password = ######

So the github.prefix should say "https:", not "git+https:".
Reply all
Reply to author
Forward
0 new messages