tbaxter / python-card-me Goto Github PK
View Code? Open in Web Editor NEWSimplifies the process of parsing and creating iCalendar and vCard objects in Python.
Simplifies the process of parsing and creating iCalendar and vCard objects in Python.
edit: The fix for this is to install directly from the git repository, PyPI release is not the latest code on master. Leaving the below for @tBaxter reference.
Good Day TBaxter,
Thank you for a the project. I had been using it fine with python2, but a migration to python3 is tripping me up and I'm not sure how to fix it. I hope you can help.
The exception:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/profiles/testuser/vcard/
Django Version: 2.2.8
Python Version: 3.6.9
Installed Applications:
['whitenoise.runserver_nostatic',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.admin',
'crispy_forms',
'allauth',
'allauth.account',
'allauth.socialaccount',
'rest_framework',
'django_celery_beat',
'ckeditor',
'import_export',
'sorl.thumbnail',
'django_countries',
'cities_light',
'django_select2',
'photologue',
'sortedm2m',
'reversion',
'notifications',
'lifconnect.users.apps.UsersConfig',
'lifconnect.invitations',
'lifconnect.events',
'lifconnect.general',
'compressor',
'kombu.transport.redis',
'debug_toolbar',
'django_extensions']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'lifconnect.general.middleware.StaffMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware']
Traceback:
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/contextlib.py" in inner
52. return func(*args, **kwds)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
21. return view_func(request, *args, **kwargs)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
21. return view_func(request, *args, **kwargs)
File "/home/myuser/dev/vedantaworld/myproject/lifconnect/users/views.py" in create_vcard
113. user.profile.vcard().serialize(), content_type="text/vcard"
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/base.py" in serialize
216. return behavior.serialize(self, buf, lineLength, validate)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/behavior.py" in serialize
162. out = base.defaultSerialize(transformed, buf, lineLength)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/base.py" in defaultSerialize
966. child.serialize(outbuf, lineLength, validate=False)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/base.py" in serialize
216. return behavior.serialize(self, buf, lineLength, validate)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/vcard.py" in serialize
214. VCardTextBehavior.serialize(obj, buf, lineLength, validate)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/behavior.py" in serialize
162. out = base.defaultSerialize(transformed, buf, lineLength)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/base.py" in defaultSerialize
974. obj.behavior.encode(obj)
File "/home/myuser/.virtualenvs/myproject/lib/python3.6/site-packages/card_me/vcard.py" in encode
140. line.value = line.value.encode('base64').replace('\n', '')
Exception Type: AttributeError at /profiles/testuser/vcard/
Exception Value: 'bytes' object has no attribute 'encode'
This is how I'm creating the card (it works fine):
def vcard(self):
the_card = card_me.vCard()
the_card.add("n")
the_card.n.value = card_me.vcard.Name(given=self.user.name)
the_card.add("fn")
the_card.fn.value = u"%s" % (self.user.name)
the_card.add("email")
the_card.email.value = self.user.email
the_card.email.type_param = "WORK"
the_card.add("tel")
the_card.tel.value = "%s" % self.mobile_number
the_card.tel.type_param = "WORK"
the_card.add("adr")
the_card.adr.value = card_me.vcard.Address(country=(self.country.name,))
the_card.adr.type_parm = "HOME"
the_card.add("photo")
buf = BytesIO()
img = Image.open(self.image.file)
img.thumbnail((600, 600), Image.ANTIALIAS)
img.save(buf, img.format)
the_card.photo.value = buf.getvalue()
the_card.photo.encoding_param = "b"
the_card.photo.type_param = img.format
if self.company_name:
the_card.add("org")
# we need to do this like this because of the way this is serialised
the_card.org.value = (self.company_name,)
if self.website:
the_card.add("url")
the_card.url.value = self.website
return the_card
However, when trying to serialize as so the problem occurs:
@login_required
def create_vcard(request, username):
user = get_object_or_404(User, username=username, is_staff=False)
response = HttpResponse(
user.profile.vcard().serialize(), content_type="text/vcard" # problem occurs here
)
filename = "contact.vcf"
response["Filename"] = filename
response["Content-Disposition"] = "attachment; filename=%s" % filename
return response
Thanks again for the project. Apologies if this is the wrong place to ask this.
The info in the README refers to a vobject
module that is not present in this project.
Looks like we need to update the doc :)
It would be nice to have a link to the repository on pypi
Hi,
seems like vobject finally got an update (https://pypi.python.org/pypi/vobject/0.9.2) and it seems to be in good shape. What's the relation to card-me? I think it would be great to merge both projects again, what do you think?
Issue has been logged with dateutil
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.