I keep getting an error when attempting to call the imported function through flask/python: AttributeError: 'function' object has no attribute 'SubToNewsletter'.
I am not quite sure what is wrong here, since it looks to me like I am importing everything properly... ANY help would be useful and extremely appreciated, I am slumped.
I am importing all of the functions and calling one of them, so I've no idea what's wrong. Additionally, the module name and the function name are not the same, and it looks to me like I am correctly calling a function that I defined in the imported module, but that is still giving me an error...
from __future__ import print_function
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint
from constants import api_key
def SubToNewsletter(email):
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = api_key
api_instance = sib_api_v3_sdk.ContactsApi(sib_api_v3_sdk.ApiClient(configuration))
create_contact = sib_api_v3_sdk.CreateContact(email=email, list_ids=[5])
try:
api_response = api_instance.create_contact(create_contact)
confirmEmail(email)
except ApiException as e:
print("Exception when calling ContactsApi->create_contact: %s\n" % e)
from flask import Flask, redirect, url_for, render_template, request, flash
import subNewsletter, unsubNewsletter
# import bcrypt, sys
app = Flask(__name__)
@app.route("/")
@app.route("/home")
def home():
return render_template("index.html")
@app.route("/subscribe", methods=["POST", "GET"])
def subNewsletter():
email = request.form.get("email")
subNewsletter.SubToNewsletter(email)
return redirect("/")