Bug 5804 - Simple pull causes: AttributeError: 'str' object has no attribute 'decode'
Summary: Simple pull causes: AttributeError: 'str' object has no attribute 'decode'
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: PC Linux
: wish feature
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-23 19:56 UTC by Oliver
Modified: 2018-03-05 00:00 UTC (History)
2 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver 2018-02-23 19:56 UTC
Hi,

the Hg version that came with Ubuntu 14.04 (2.8.2) failed to pull from the official Hg repo, because bundle2 support was missing.

So I decided to install Mercurial using `pip install --user mercurial`.

After installing I see this:

-------------------------------
$ hg --version
Mercurial Distributed SCM (version 4.5)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2018 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-------------------------------

When I then attempted to pull again, I was met with an exception as follows:

-------------------------------
$ hg pull
pulling from https://www.mercurial-scm.org/repo/hg
** unknown exception encountered, please report by visiting
** https://mercurial-scm.org/wiki/BugTracker
** Python 3.6.4 (default, Jan  1 2018, 22:34:23) [GCC 4.8.4]
** Mercurial Distributed SCM (version 4.5)
** Extensions loaded: extdiff, fetch, strip, mq, purge, rebase, record, schemes, shelve, transplant
Traceback (most recent call last):
  File "/home/oliver/.local/bin/hg", line 41, in <module>
    dispatch.run()
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 88, in run
    status = (dispatch(req) or 0) & 255
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 183, in dispatch
    ret = _runcatch(req)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 324, in _runcatch
    return _callcatch(ui, _runcatchfunc)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 332, in _callcatch
    return scmutil.callcatch(ui, func)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/scmutil.py", line 154, in callcatch
    return func()
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 314, in _runcatchfunc
    return _dispatch(req)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 918, in _dispatch
    cmdpats, cmdoptions)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 673, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 926, in _runcommand
    return cmdfunc()
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/dispatch.py", line 915, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/util.py", line 1195, in check
    return func(*args, **kwargs)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/util.py", line 1195, in check
    return func(*args, **kwargs)
  File "/home/oliver/.local/lib/python3.6/site-packages/hgext/mq.py", line 3583, in mqcommand
    return orig(ui, repo, *args, **kwargs)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/util.py", line 1195, in check
    return func(*args, **kwargs)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/util.py", line 1195, in check
    return func(*args, **kwargs)
  File "/home/oliver/.local/lib/python3.6/site-packages/hgext/rebase.py", line 1772, in pullrebase
    ret = orig(ui, repo, *args, **opts)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/util.py", line 1195, in check
    return func(*args, **kwargs)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/commands.py", line 3989, in pull
    other = hg.peer(repo, opts, source)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/hg.py", line 181, in peer
    return _peerorrepo(rui, path, create).peer()
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/hg.py", line 156, in _peerorrepo
    obj = _peerlookup(path).instance(ui, path, create)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/httppeer.py", line 497, in instance
    inst._fetchcaps()
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/httppeer.py", line 239, in _fetchcaps
    self._caps = set(self._call('capabilities').split())
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/httppeer.py", line 407, in _call
    fp = self._callstream(cmd, **args)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/httppeer.py", line 336, in _callstream
    resp = self._openurl(req)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/httppeer.py", line 193, in _openurl
    ret = self._urlopener.open(req)
  File "/home/oliver/.pyenv/versions/3.6.4/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/home/oliver/.pyenv/versions/3.6.4/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/home/oliver/.pyenv/versions/3.6.4/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/url.py", line 342, in https_open
    user, password = self.pwmgr.find_stored_password(url)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/url.py", line 96, in find_stored_password
    return self.passwddb.find_user_password(None, authuri)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/ui.py", line 182, in find_user_password
    _maybestrurl(uri)))
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/ui.py", line 153, in _maybestrurl
    return pycompat.strurl(maybebytes)
  File "/home/oliver/.local/lib/python3.6/site-packages/mercurial/pycompat.py", line 183, in strurl
    return url.decode(u'ascii')
AttributeError: 'str' object has no attribute 'decode'
-------------------------------

Let me know if more information is required.

Best regards,

Oliver
Comment 1 Gregory Szorc 2018-02-23 20:45 UTC
Mercurial doesn't yet support Python 3.

The bug here is that setup.py allows install to proceed with Python 3.

IMO the official source distribution should disallow Python 3 in setup.py. I'll work on a patch for stable.
Comment 2 HG Bot 2018-02-24 11:20 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/fb39f6a8a864
Gregory Szorc <gregory.szorc@gmail.com>
setup: only allow Python 3 from a source checkout (issue5804)

People are running `pip install Mercurial` with Python 3 and that
is working because not everything performs a Python version
compatibility check.

Modern versions of pip do recognize the "python_requires" keyword
(https://packaging.python.org/tutorials/distributing-packages/#python-requires)
which we set if using setuptools. But this isn't set nor recognized
everywhere.

To prevent people from accidentally installing Mercurial with Python
3 until Python 3 is officially supported, have setup.py fail when
run with Python 3. But don't fail if we're running from a source
checkout, as we don't want to anger Mercurial developers hacking
on Python 3 nor Mercurial's test automation running from source
checkouts. People running setup.py from source checkouts could still
fall through a Python 3 crack. But at least the
`pip install Mercurial` attempt will get nipped in the bud.

(please test the fix)
Comment 3 Oliver 2018-02-25 07:23 UTC
I see, I did not realize that Python 3 wasn't supported. A warning would also have been in order, btw. Doesn't have to be prevented outright. It's just that it looked as if the installation was successful and then it ended up failing.

Also, not sure if you meant that I should be testing the fix. It doesn't seem to be in the mercurial-4.5.tar.gz, however. So it's still successfully installing for me (I cleared the pip cache!).

$ pip install --user mercurial
Collecting mercurial
  Downloading mercurial-4.5.tar.gz (5.9MB)
    100% |████████████████████████████████| 5.9MB 28kB/s
Installing collected packages: mercurial
  Running setup.py install for mercurial ... done
Successfully installed mercurial-4.5
Comment 4 Gregory Szorc 2018-02-25 15:58 UTC
No testing is needed on your part. The fix will be in Mercurial 4.5.1, which will be released February 6. (Normally it would be February 1, but we're having a developer meet-up this weekend and we don't want to release when people are traveling.)
Comment 5 Bugzilla 2018-03-05 00:00 UTC
Bug was set to TESTING for 7 days, resolving