Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when Attribute doesn't exist #46

Closed
aneroid opened this issue Jun 15, 2012 · 2 comments
Closed

TypeError when Attribute doesn't exist #46

aneroid opened this issue Jun 15, 2012 · 2 comments
Assignees
Labels

Comments

@aneroid
Copy link

aneroid commented Jun 15, 2012

Hi @jacquev6 When a github user's name has not been entered, I get a TypeError:
TypeError: coercing to Unicode: need string or buffer, NoneType found

Using:

user = gh.get_user('username')
print user.id
print user.login + ' -> ' + user.name

Also happens with getattr:

print getattr(user, u'login') + ' -> ' + getattr(user, u'name', u'No name entered')
#(or)
print getattr(user, 'login') + ' -> ' + getattr(user, 'name', 'No name entered')

Is this the expected behaviour for missing (non-mandatory) attributes? I used except TypeError: as a workaround.

@jacquev6
Copy link
Member

Hello, when the user has not set his name, user.name is None, so you can't concatenate it with a string. The exception is not raised by PyGithub but by your code. Try print user.login, "->", user.name to avoid string concatenation.

@ghost ghost assigned jacquev6 Jun 15, 2012
@aneroid
Copy link
Author

aneroid commented Jun 15, 2012

Perfect! Thanks, that worked. I knew + for string concatenation was evil...did not listen.

@aneroid aneroid closed this as completed Jun 15, 2012
@aneroid aneroid added the v1 label Mar 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants