Could not able to import stripe

Submitted 3 years, 11 months ago
Ticket #11
Views 549
Language/Framework Django
Priority Low
Status Closed

System check identified no issues (0 silenced).
May 28, 2020 - 13:23:50
Django version 3.0.6, using settings 'ecommerce.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /cart/checkout/
Traceback (most recent call last):
  File "C:\Users\Mahesh\himalaya\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\Mahesh\himalaya\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Mahesh\himalaya\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Mahesh\himalaya\ecommerce\carts\views.py", line 89, in checkout_home
    did_charge, crg_msg = billing_profile.charge(order_obj)
  File "C:\Users\Mahesh\himalaya\ecommerce\billing\models.py", line 46, in charge
    return Charge.objects.do(self, order_obj, card)
  File "C:\Users\Mahesh\himalaya\ecommerce\billing\models.py", line 107, in do
    c = stripe.Charge.create(
NameError: name 'stripe' is not defined

Submitted on May 29, 20
add a comment

1 Answer

Verified

Acknowledged.assigned to our techie

Submitted 3 years, 11 months ago

Please confirm below steps,

Is your virtual env activated? Did you install stripe package??. If yes , what is the package you installed? Show me the import & usage code ?

- scott 3 years, 11 months ago

yes it is installed and activated. (himalaya) C:\Users\Mahesh\himalaya\ecommerce>pip freeze asgiref==3.2.7 astroid==2.4.1 certifi==2020.4.5.1 chardet==3.0.4 colorama==0.4.3 Django==3.0.6 djangorestframework==3.11.0 idna==2.9 isort==4.3.21 lazy-object-proxy==1.4.3 mccabe==0.6.1 Pillow==7.0.0 pylint==2.5.2 pytz==2019.3 requests==2.23.0 six==1.15.0 somepackage==1.2.3 sqlparse==0.3.1 stripe==2.48.0 toml==0.10.1 typed-ast==1.4.1 urllib3==1.25.9 wrapt==1.12.1

(himalaya) C:\Users\Mahesh\himalaya\ecommerce>

- maheshbist111 3 years, 11 months ago

NameError at /cart/checkout/ name 'stripe' is not defined Request Method: POST Request URL: http://127.0.0.1:8000/cart/checkout/ Django Version: 3.0.6 Exception Type: NameError Exception Value:
name 'stripe' is not defined Exception Location: C:\Users\Mahesh\himalaya\ecommerce\billing\models.py in do, line 107 Python Executable: C:\Users\Mahesh\himalaya\Scripts\python.exe Python Version: 3.7.4 Python Path:
['C:\Users\Mahesh\himalaya\ecommerce', 'C:\Users\Mahesh\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\Mahesh\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\Mahesh\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\Mahesh\AppData\Local\Programs\Python\Python37-32', 'C:\Users\Mahesh\himalaya', 'C:\Users\Mahesh\himalaya\lib\site-packages'] Server time: Thu, 28 May 2020 07:55:26 +0000 Traceback Switch to copy-and-paste view C:\Users\Mahesh\himalaya\lib\site-packages\django\core\handlers\exception.py in inner response = get_response(request) … ▶ Local vars C:\Users\Mahesh\himalaya\lib\site-packages\django\core\handlers\base.py in _get_response response = self.process_exception_by_middleware(e, request) … ▶ Local vars C:\Users\Mahesh\himalaya\lib\site-packages\django\core\handlers\base.py in _get_response response = wrapped_callback(request, callback_args, *callback_kwargs) … ▶ Local vars C:\Users\Mahesh\himalaya\ecommerce\carts\views.py in checkout_home did_charge, crg_msg = billing_profile.charge(order_obj) … ▶ Local vars C:\Users\Mahesh\himalaya\ecommerce\billing\models.py in charge return Charge.objects.do(self, order_obj, card) … ▶ Local vars C:\Users\Mahesh\himalaya\ecommerce\billing\models.py in do c = stripe.Charge.create( … ▶ Local vars

- maheshbist111 3 years, 11 months ago

show me the views.py code where its imported & used

- Vengat 3 years, 11 months ago

import stripe

from django.http import JsonResponse, HttpResponse from django.shortcuts import render, redirect from django.utils.http import is_safe_url

stripe.api_key = "sk_test_kKKjtffSyYqvfFFw3ifXaLth00G0ia6Ke1" STRIPE_PUB_KEY = 'pk_test_blksRJqozhNmHJhS50p8eqLc00Tebc1PTT'

from .models import BillingProfile, Card

def payment_method_view(request): # if request.user.is_authenticated(): # billingprofile = request.user.billingprofile # my_customer_id = billing_profile.my_customer_id billing_profile, billing_profile_created = BillingProfile.objects.new_or_get(request) if not billing_profile: return redirect("/cart") next_url = None next_ = request.GET.get('next') if is_safe_url(next_, request.get_host()): next_url = next_ return render(request, 'billing/payment-method.html', {"publish_key": STRIPE_PUB_KEY, "next_url": next_url})

def payment_method_createview(request): if request.method == "POST" and request.is_ajax(): billing_profile, billing_profile_created = BillingProfile.objects.new_or_get(request) if not billing_profile: return HttpResponse({"message": "Cannot find this user"}, status_code=401) token = request.POST.get("token") if token is not None: customer = stripe.Customer.create(billing_profile.customer_id) card_response = customer.sources.create(source=token) new_card_obj = Card.objects.add_new(billing_profile, card_response) print(new_card_obj) return JsonResponse({"message": "Success! Your card was added."}) return HttpResponse("error", status_code=401)

- maheshbist111 3 years, 11 months ago

little confuse,, which view you are getting an error?

- Vengat 3 years, 11 months ago

also make sure to use markup language when you paste the code ,.. that help us to grab the code and take a look

- Vengat 3 years, 11 months ago

Views.py in billing folder

- maheshbist111 3 years, 11 months ago

no i mean function name you are caling and getting this error.. because i installed stripe my end .. i dont see any issue.. so atleast there is no issue in package... problem may be how you are using in your view

- Vengat 3 years, 11 months ago

After adding card When I go for submit checkout I get this error...

- maheshbist111 3 years, 11 months ago

After adding card When I go for submit checkout I get this error...

- maheshbist111 3 years, 11 months ago

I can able to add card and customer details

- maheshbist111 3 years, 11 months ago

ok please provide me the URL & view details(i mean function details) submit button calling

- Vengat 3 years, 11 months ago

http://127.0.0.1:8000/cart/checkout/

- maheshbist111 3 years, 11 months ago

once i click submit after i got error

- maheshbist111 3 years, 11 months ago

no .. you are not get my point ..ok send me the html file, urls.py & views.py.. send me to learnswvarn@gmail.com

- Vengat 3 years, 11 months ago

I sent an email

- maheshbist111 3 years, 11 months ago

can we connect in zoom meeting?.. because i dont understand the issue

- Vengat 3 years, 11 months ago

Sure

- maheshbist111 3 years, 11 months ago

may be we connect at 9.45 PM PST.. i will send you the zoom link

- Vengat 3 years, 11 months ago

sent you the meeting link. will connect in 15 mins

- Vengat 3 years, 11 months ago

Sure...IAM from Nepal so is this time (9:45)according to my time zone or yours...

- maheshbist111 3 years, 11 months ago

15 mins from now .. we are from USA

- Vengat 3 years, 11 months ago

can you join now?

- Vengat 3 years, 11 months ago

Yes .. surely

- maheshbist111 3 years, 11 months ago

as discussed, issue has been resolved after import the stripe in models.py . So please go ahead and close the ticket. As you can always support us Donate . If you want :)

- Vengat 3 years, 11 months ago


Latest Blogs