Comments (6)
@alanhamlett,
Thanks for opening this issue. Could you share more details about your use case and integration with Braintree so we can better evaluate this change? Currently the Braintree Python client library as a whole favors str
over basestring
.
from braintree_python.
Sometimes I pass strings from SQLAlchemy, which prefers unicode
over str
, and from WTForms, which also prefers unicode
over str
. I'm not sure which attribute caused the error, but it was when changing the quantity in the addons array when updating a subscription.
from braintree_python.
Thanks for clarifying your use case. We'll discuss this change and let you know if we have any further questions.
from braintree_python.
Hi @alanhamlett,
We've discussed this internally and we will be retaining str
as we want encoded strings instead of unicode. I'm closing this issue, but thanks for reaching out.
from braintree_python.
Ok, just want to say that str
should only be used when writing to disk, network, or other things external to Python. unicode
is the preferred way to handle any string in Python.
When you’re dealing with text manipulations (finding the number of characters in a string or cutting a string on word boundaries) you should be dealing with unicode strings as they abstract characters in a manner that’s appropriate for thinking of them as a sequence of letters that you will see on a page. When dealing with I/O, reading to and from the disk, printing to a terminal, sending something over a network link, etc, you should be dealing with byte str as those devices are going to need to deal with concrete implementations of what bytes represent your abstract characters.
For example as soon as you get a string from the user or from the network, convert it to unicode
:
https://pythonhosted.org/kitchen/unicode-frustrations.html#convert-text-at-the-border
I've noticed usage of both unicode
and str
in this library. You should standardize the usage of unicode
vs str
throughout the library.
You're going to run into a lot of cases where unicode
is needed (emails can contain unicode characters) so it's best to standardize on unicode
instead of str
. Having to somehow guess which string type this library is expecting is a recipe for exceptions.
from braintree_python.
Also, the 2 most popular Python web frameworks[1] both default to unicode
and both convert user input to unicode
. For example a payment processor token from braintree.js
is automatically treated as unicode
and it goes against conventions to have to convert back to str
when passing strings to braintree_python
.
- Django and Flask are in my experience the 2 most popular Python web frameworks
from braintree_python.
Related Issues (20)
- gateway.transaction.find raises a TypeError when initialised with client_id and secret HOT 2
- Respect the requests_ca_bundle environment variable HOT 2
- Transaction using nonce fails but payment method gets vaulted with option "store_in_vault_on_success" HOT 1
- Is this library thread-safe? HOT 3
- Connection pooling HOT 3
- Module fails on import HOT 1
- TypeError: can only concatenate str (not "NoneType") to str HOT 1
- Braintree created subscription not showing in sandox account HOT 3
- Print transactions in JSON format HOT 4
- Headers provided by braintree http util contain mixture of str/bytes HOT 2
- Remove universal wheel, python 2 is unsupported HOT 2
- Use python_requires='>=3.5' HOT 2
- Paypal credit
- strings with special regex characters are causing a DeprecationWarning HOT 3
- Include updated_at field in TransactionSearch HOT 2
- Go SDK + CloudQuery source plugin? HOT 1
- Can't upgrade to Braintree 4.18.1 / Python 3.10.9 (DeprecationWarning: Use ProtectionLevel enum instead) HOT 11
- braintree python sdk support initWithAuthorization/initWIthAPIClient like iOS SDK and receive client token as argues? HOT 1
- Unittest failures on Python 3.12 HOT 1
- Expose error details in "UnexpectedException" in Python library HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from braintree_python.