Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

"ImportError: cannot import name 'Connection' #39

Open

Description

@julianl28

Sorry if this is really obvious, I'm new to Python. When I try to import the bitly_api library into my application I get the above error. To narrow down the problem (in case it was one of the other libraries I was using) I created a new program with just 'import bitly_api' in it, nothing else. I still get the error below.

`"C:\Program Files\Python35\python.exe" C:/Users/julianl/Documents/Python/test_bitly_api.py
Traceback (most recent call last):
File "C:/Users/julianl/Documents/Python/test_bitly_api.py", line 12, in
import bitly_api
File "C:\Program Files\Python35\lib\site-packages\bitly_api__init__.py", line 1, in
from bitly_api import Connection, BitlyError, Error
ImportError: cannot import name 'Connection'

Process finished with exit code 1`

I'm on Windows 10, Python 3.5.1, using the PyCharm Community Edition 2016.2.3 IDE, and bitly_api library v0.3.

Activity

  1. jawwolfe commented on Nov 14, 2016

    @jawwolfe

    Hi. I'm having the same problem with using python 3.5.2 with bitly_api.

  2. mithun-dhali-cookifi commented on Dec 1, 2016

    @mithun-dhali-cookifi

    from bitly_api import bitly_api
    python 3.5 windows
    +1

  3. Edgar-I commented on Dec 10, 2016

    @Edgar-I

    Approved. Windows 10 x64, PyCharm 2016.3 Python 3.5.2

  4. Edgar-I commented on Dec 11, 2016

    @Edgar-I

    @scott-plutovr @mithun-dhali-cookifi @jawwolfe @julianl28
    Roughly fixed. No guaranteed backward compability. Use on your own risk.
    Tested on Python 3.5.2
    Problem with imports and unicode
    https://goo.gl/AYsH7H

  5. browniebroke commented on Dec 20, 2016

    @browniebroke

    I had the same problem and given the lack of support for this library, I've switched to https://github.com/ellisonleao/pyshorteners

    • Uses requests, so easier to mock API calls for testing
    • Works with Python 3.5
    • Looks like it's still maintained (last activity on September)

    It arguably adds some code I don't need for the others shorteners, but if one day I want to switch to another service, there is normalised API.

  6. szabgab commented on Dec 27, 2016

    @szabgab

    Same problem on OSX using Python 3.5.2
    @TheGuyverjoke is there a pull-request with the changes that created the zip file linked to?

  7. mithun-dhali-cookifi commented on Dec 27, 2016

    @mithun-dhali-cookifi

    I ended up using my own small snippet. Since it was not that complex i avoided using any lib.

    
    def shorten(uri):
        query_params = {
            'access_token': settings.BITLY_OAUTH2_TOKEN,
            'longUrl': uri
        }
    
        endpoint = 'https://api-ssl.bitly.com/v3/shorten'
        response = requests.get(endpoint, params=query_params, verify=False)
    
        data = response.json()
    
    
        if not data['status_code'] == 200:
            logger.error("Unexpected status_code: {} in bitly response. {}".format(data['status_code'], response.text))
    
        return data['data']['url']
    
    
  8. Edgar-I commented on Dec 28, 2016

    @Edgar-I

    @szabgab You can use code from master branch. Since PyPI has non >Python3.5 compatible code with tag v0.3

  9. szabgab commented on Dec 29, 2016

    @szabgab

    @TheGuyverjoke thanks. For now I am good with the snippet provided by @mithun-dhali-cookifi

  10. VISWESWARAN1998 commented on Aug 24, 2017

    @VISWESWARAN1998

    @mithun-dhali-cookifi that one has a requests dependency and the url is not encoded so longer urls which contains &, ? will not be shortened.

    Here is an improved solution: https://gist.github.com/VISWESWARAN1998/24af6f2aa01f43f84c6850718593deb3

  11. mithun-dhali-cookifi commented on Aug 24, 2017

    @mithun-dhali-cookifi

    @VISWESWARAN1998

    http://docs.python-requests.org/en/master/user/quickstart/#passing-parameters-in-urls
    params are automatically escaped/encoded by requests.
    The solution is functionally correct and we have been using it on our production site.

    The implementation does require requests. But since requests is very popular and we were already using it, it made sense for us.

    There may be some new library available. I have not checked recently.

  12. jimmy927 commented on May 13, 2019

    @jimmy927

    This repo seems abandoned by its original creator.
    I have cloned it and merged in at least some pull requests here: https://github.com/jimmy927/bitly-api-python

    At the writing point in time i got it working.

  13. geotheory commented on May 21, 2019

    @geotheory

    @jimmy927 I've cloned on macOS and installed (pip install --upgrade -e /pathto/bitly-api-python/), but get No module named 'bitly_api' error when importing. Any idea what the issue is?

  14. jimmy927 commented on May 21, 2019

    @jimmy927

    @jimmy927 I've cloned on macOS and installed (pip install --upgrade -e /pathto/bitly-api-python/), but get No module named 'bitly_api' error when importing. Any idea what the issue is?

    My clone is not available on PyPI ( i think ...)
    So run this instead: pip install git+git://github.com/jimmy927/bitly-api-python

    I changed the documentation accordingly.

  15. geotheory commented on May 21, 2019

    @geotheory

    Awesome that worked - cheers :)

  16. BRAINIFII commented on Sep 5, 2019

    @BRAINIFII

    Had the same issue but the API provided by @jimmy927 worked perfectly you saved my life.

  17. vjcalel commented on Feb 19, 2020

    @vjcalel

    @jimmy927

    Perhaps you could release it on pypi. How to include this on requirement.txt for a herku python app ?

  18. jimmy927 commented on Feb 19, 2020

    @jimmy927

    @jimmy927

    How to include this on requirement.txt for a herku python app ?

    Does it work if you put "git+git://github.com/jimmy927/bitly-api-python" in your requirements.txt ?
    I works for me on Google App Engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions