pasting an URL into gwibber fails if there's an error with the URL shortening services

Bug #314426 reported by Mihai Secasiu
4
Affects Status Importance Assigned to Milestone
Gwibber
Fix Released
Medium
Unassigned

Bug Description

I tried to paste an URL into gwibber text box but nothing showed up.
After starting gwibber from terminal I can see the following error whenever I try to paste in an URL:

Traceback (most recent call last):
  File "/usr/local/lib/python2.5/site-packages/gwibber/client.py", line 225, in on_add_text
    short = urllib2.urlopen("http://is.gd/api.php?longurl=%s" % text).read()
  File "/usr/lib/python2.5/urllib2.py", line 124, in urlopen
    return _opener.open(url, data)
  File "/usr/lib/python2.5/urllib2.py", line 387, in open
    response = meth(req, response)
  File "/usr/lib/python2.5/urllib2.py", line 498, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.5/urllib2.py", line 425, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.5/urllib2.py", line 506, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error

Clearly this was a problem with the is.gd server api, cause after a few minutes it worked again
Then I noticed another problem. I had "Automatically shorten Urls" enabled and I tried to post a tinyurl. Seems like this makes is.gd always fail with a 500 internal error.

I think gwibber should just paste the link as it is if it get's an error from the url shortening service and it should do a better job at identifying know shortening services and if the url is already shortenend it should not try to shorten it again.

Related branches

Revision history for this message
Ryan Paul (segphault) wrote :

Yep, I can replicate this. The reason why it consistently fails when you paste in a tinyurl link is because is.gd blacklists other shortening and redirection sites in order to prevent people from chaining shortened URLs.

I concur with your suggestions for error handling and proper fallback behavior. I'll try to implement this soon.

Changed in gwibber:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Dominic Evans (oldmanuk) wrote :

That's actually quite a good feature of is.gd. If you're pasting in an already shortened url then you wouldn't want the url shortened again.

Perhaps we should maintain our own list of 'blacklisted' domains (tinyurl, bit.ly etc.) so the url isn't even submitted to is.gd at all.

Revision history for this message
Evan McClain (aeroevan) wrote :

Well, this patch should fix the bug. It just adds a try/except/else catch. It also temporarily turns off the shorten_url preference to prevent an infinite loop.
It may not be the best solution, but it should work....

Revision history for this message
Evan McClain (aeroevan) wrote :

Fixed an (unrelated) bug when trying to shorten this bug's url. Apparently is.gd doesn't like the + in the url. This patch now fixes the url shorten as well as the is.gd api not liking things like + in urls. I should probably open a new bug for this, but I don't want to screw up the diffs.

Revision history for this message
Ryan Paul (segphault) wrote :

I adapted Evan's patch and applied it in revision 210. Gwibber will automatically insert the original URL if the is.gd API call fails. It will also check the length of the URL and only try to shorten if it is longer than 20 characters.

Changed in gwibber:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.