'NoneType' object has no attribute 'rfind'

1,837 views
Skip to first unread message

bfellows

unread,
Feb 4, 2009, 2:32:31 PM2/4/09
to Django users
I've run into what strikes me as an odd exception when using the gdata-
python-client library in Django 1.0 on Python 2.5 and the dev
environment server.

For context, this is a very simple sandbox app for playing with the
picasa web album API. It contains no data models. I have my urls set
up to match the "blah" part in http://project/app/blah/ and send it to
the view function as the "bla_id" param, which is used to specify
which picasa photos are retrieved by tag.

The view looks a little like:

#
def app_view(request, blah_id):
gd_client = gdata.photos.service.PhotosService()
photos = gd_client.GetFeed('/data/feed/api/user/%s/albumid/%s?
kind=photo&tag=%s' % ('username', 'album id', blah_id)
return render_to_response('/app/app_view.html', {'photo_list':
photos.entry})
#

and python throws:
Exception Type: AttributeError at /app/blah/
Exception Value: 'NoneType' object has no attribute 'rfind'

The line at fault appears to be the one with the GetFeed query.

While shuffling the code around, I can return a HttpResponse(blah_id)
and it will display the text I've fed the url. I can also hard code
"blah" in the GetFeed call and it will function as desired, which
makes me think it may have to do with some type conversion gotchas
involving the blah_id param I am not up to speed on or something.

I've googled this exception and few of them are specific to django. So
I am not sure if what I am looking at is a problem with my mad python
skillz (which it very well could be) or a problem with Django or what.

Any advice?

bfellows

unread,
Feb 4, 2009, 2:37:31 PM2/4/09
to Django users
Traceback:
File "/var/lib/python-support/python2.5/django/core/handlers/base.py"
in get_response
86. response = callback(request, *callback_args, **callback_kwargs)
File "/var/django/.../views.py" in display
33. photos = gd_client.GetFeed(f)
File "/usr/lib/python2.5/site-packages/gdata/photos/service.py" in
GetFeed
177. return self.Get(uri, converter=gdata.photos.AnyFeedFromString)
File "/usr/lib/python2.5/site-packages/gdata/service.py" in Get
981. headers=extra_headers)
File "/usr/lib/python2.5/site-packages/atom/service.py" in request
176. data=data, headers=all_headers)
File "/usr/lib/python2.5/site-packages/atom/http_interface.py" in
perform_request
148. return http_client.request(operation, url, data=data,
headers=headers)
File "/usr/lib/python2.5/site-packages/atom/http.py" in request
93. connection = self._prepare_connection(url, all_headers)
File "/usr/lib/python2.5/site-packages/atom/http.py" in
_prepare_connection
249. return HttpClient._prepare_connection(self, url, headers)
File "/usr/lib/python2.5/site-packages/atom/http.py" in
_prepare_connection
161. return httplib.HTTPConnection(url.host)
File "/usr/lib/python2.5/httplib.py" in __init__
639. self._set_hostport(host, port)
File "/usr/lib/python2.5/httplib.py" in _set_hostport
645. i = host.rfind(':')

Karen Tracey

unread,
Feb 4, 2009, 2:50:22 PM2/4/09
to django...@googlegroups.com

And the exception info from your other message is:


> Exception Type: AttributeError at /app/blah/
> Exception Value: 'NoneType' object has no attribute 'rfind'

So, host is None down in the depths of the library code.  Looking further up, we see something passing url.host, so host is somehow supposed to be associated with a url involved here.  Is the url you are passing in supposed to be able to be split into host[:port]/path?  (I know nothing of this GetFeed method you are calling here.)  If so, it doesn't look like you have provided the host portion.  That's just a guess, it could well be wrong.  One way to figure out what it's supposed to be is to look at the sources identified in that traceback -- all the files and line numbers are identified there -- and figure out where host is supposed to be coming from, which should reveal what you need to do to get it set properly.

Karen

 

bfellows

unread,
Feb 4, 2009, 11:38:03 PM2/4/09
to Django users
Looks like I figured it out, it was my mad Python skillz. I cast the
blah_id object as a string when feeding it to the GetFeed function.
Works now.

On Feb 4, 11:50 am, Karen Tracey <kmtra...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages