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: cannot make memory view because object does not have the buffer interface #62

Closed
alanhamlett opened this issue Oct 22, 2015 · 11 comments

Comments

@alanhamlett
Copy link

This error happens when running braintree.Customer.create({'email': email}) where email is the user's email address.

Traceback (most recent call last):
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/flask_login.py", line 792, in decorated_view
    return func(*args, **kwargs)
  File "/opt/wakatime/current/app/api_v1.py", line 295, in post_users_current_payment_method
    app.current_user.update_payment_method(processor_type, **form.data)
  File "/opt/wakatime/current/app/models.py", line 924, in update_payment_method
    self.processor.update_payment_method(kwargs['token'])
  File "/opt/wakatime/current/app/models.py", line 3435, in update_payment_method
    'customer_id': self.customer.id,
  File "/opt/wakatime/current/app/models.py", line 3319, in customer
    self._customer = PaymentProcessor.get_customer(self.user, self.type)[0]
  File "/opt/wakatime/current/app/models.py", line 3294, in get_customer
    'email': user.email,
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer.py", line 102, in create
    return Configuration.gateway().customer.create(params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer_gateway.py", line 26, in create
    return self._post("/customers", {"customer": params})
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer_gateway.py", line 88, in _post
    response = self.config.http().post(self.config.base_merchant_path() + url, params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 49, in post
    return self.__http_do("POST", path, params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 72, in __http_do
    raise e
TypeError: cannot make memory view because object does not have the buffer interface
@alanhamlett
Copy link
Author

I'm now passing wrap_http_exceptions=True to braintree.Configuration.configure to get a better error message. This is happening consistently for the same user.

@alanhamlett
Copy link
Author

After wrapping http exceptions, I'm getting an UnexpectedError.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "app/models.py", line 3378, in customer
    self._customer = PaymentProcessor.get_customer(self.user, self.type)[0]
  File "app/models.py", line 3353, in get_customer
    'email': user.email,
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer.py", line 102, in create
    return Configuration.gateway().customer.create(params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer_gateway.py", line 26, in create
    return self._post("/customers", {"customer": params})
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer_gateway.py", line 88, in _post
    response = self.config.http().post(self.config.base_merchant_path() + url, params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 49, in post
    return self.__http_do("POST", path, params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 70, in __http_do
    http_strategy.handle_exception(e)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 101, in handle_exception
    raise UnexpectedError(exception)
braintree.exceptions.unexpected_error.UnexpectedError: cannot make memory view because object does not have the buffer interface

@alanhamlett
Copy link
Author

The traceback was lost because raise e does not preserve context. After getting the original traceback it looks like a bug in the requests library:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "app/models.py", line 3378, in customer
    self._customer = PaymentProcessor.get_customer(self.user, self.type)[0]
  File "app/models.py", line 3353, in get_customer
    'email': user.email,
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer.py", line 102, in create
    return Configuration.gateway().customer.create(params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer_gateway.py", line 26, in create
    return self._post("/customers", {"customer": params})
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/customer_gateway.py", line 88, in _post
    response = self.config.http().post(self.config.base_merchant_path() + url, params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 49, in post
    return self.__http_do("POST", path, params)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 67, in __http_do
    status, response_body = http_strategy.http_do(http_verb, full_path, self.__headers(), request_body)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/braintree/util/http.py", line 94, in http_do
    timeout=self.config.timeout
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/api.py", line 109, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
    body=body, headers=headers)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 353, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python2.7/httplib.py", line 979, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1013, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 975, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 839, in _send_output
    self.send(message_body)
  File "/usr/lib/python2.7/httplib.py", line 811, in send
    self.sock.sendall(data)
  File "/opt/wakatime/current/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 216, in sendall
    data = memoryview(data)
TypeError: cannot make memory view because object does not have the buffer interface

@alanhamlett
Copy link
Author

Related to kennethreitz/requests#2818, waiting on urllib3 to release this fix urllib3/urllib3#719.

@po5i
Copy link

po5i commented Dec 4, 2015

This is critical 👎

@agfor
Copy link

agfor commented Dec 7, 2015

@po5i Until a fixed version of requests is released, I'd suggest downgrading to a known-good version. If you're not on Google App Engine, any version before 2.8.0 should work.

@zagfai
Copy link

zagfai commented Dec 9, 2015

OMG. when could it be fixed.

@agfor
Copy link

agfor commented Dec 9, 2015

@zagfai Please see my previous comment. A new version of requests -- 2.9.0 -- is expected soon, which should fix this issue. Until then, you'll need to downgrade to an older version of requests.

@alanhamlett
Copy link
Author

Another way is fork requests, apply the patch to your fork, then install your fork in your requirements.txt:

-e git://github.com/<you>/requests.git@<hash>#egg=requests

@agfor
Copy link

agfor commented Jan 13, 2016

@po5i @zagfai @alanhamlett

To close the loop -- requests 2.9.1 is out, and this issue should be resolved.

@alanhamlett
Copy link
Author

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants