← Back to team overview

dulwich-users team mailing list archive

Pushing to bitbucket via https generates SendPackError: unpack eof before pack header was fully read

 

Hi there,

I've been trying to get a full round trip happening from/to a repo on
bitbucket over Https. Firstly my Https client (that remembers username and
password):

---------------

class HttpsGitClient(HttpGitClient):
    USER_AGENT = 'git/1.7.9.5'

    def __init__(self, base_url, username=None, password=None, dumb=None,
*args, **kwargs):
        parsed = urlparse.urlparse(base_url)
        assert parsed.scheme in ('http', 'https')
        self.username = username or parsed.username
        self.password = password or parsed.password

        # strip username:password if its there
        if parsed.username:
            base_url = urlparse.urlunparse([parsed[0],
                                            parsed[1].split('@',1)[1],
                                            parsed[2],
                                            parsed[3],
                                            parsed[4],
                                            parsed[5]])

        return HttpGitClient.__init__(self, base_url, dumb, *args, **kwargs)

    def _perform(self, req):
        """Perform a HTTP(S) request with auth"""
        base64string = base64.encodestring('%s:%s' % (self.username,
self.password)).replace('\n', '')
        req.add_header("Authorization", "Basic %s" % base64string)

        if self.USER_AGENT:
            req.add_header('User-Agent', self.USER_AGENT)

        return HttpGitClient._perform(self,req)

-----------

This adds a user agent string (bitbuckets nginx rejects it otherwise) and
adds the authorization in the http headers.

Doing the pull as follows works fine:

        client = HttpsGitClient(url, ....)
        parse = urlparse(url)
        remote_refs = client.fetch(parse.path, self.repo,
progress=sys.stderr.write)
        self.repo['HEAD'] = remote_refs['HEAD']
        self.repo._build_tree()

Now when I try and do the push as follows:

        client = HttpsGitClient(url, ...)
        parse = urlparse(url)

        def wantmaster(oldrefs):
            return self.repo.get_refs()

        client.send_pack(parse.path, wantmaster,
self.repo.object_store.generate_pack_contents)

Traceback (most recent call last):
  File "repository.py", line 257, in <module>
    r.push('https://bitbucket.org/username/project.git',
username="username", password=sys.argv[1])
  File "/.../repository.py", line 85, in push
    self.repo.object_store.generate_pack_contents)
  File "/.../python2.7/site-packages/dulwich/client.py", line 924, in
send_pack
    progress)
  File "/.../python2.7/site-packages/dulwich/client.py", line 345, in
_handle_receive_pack_tail
    self._report_status_parser.check()
  File "/.../python2.7/site-packages/dulwich/client.py", line 99, in check
    raise SendPackError(self._pack_status)
dulwich.errors.SendPackError: unpack eof before pack header was fully read

Has anyone has any luck pushing to bitbucket using HTTPS?
What is the meaning of this error?

Regards

Crispin Wellington

Follow ups