0

I am using python requests to validate mailgun email addresses.

def validateemail(emailaddress):
    return requests.get(
        "https://api.mailgun.net/v3/address/validate",
        auth=("api", EMAILPUBLICVALIDATIONKEY ),
        params={'address': emailaddress}
    )

validation = validateemail(email)
validationtext = validation.json

validationtext contains the following response:

["{"address": "[email protected]", "did_you_mean": …: false, "is_role_address": false, "is_valid": tr", "ue, "mailbox_verification": "unknown", "parts": {"…: "assfuck.com", "local_part": "sdfhdd"}, "reason", "": null}"]
0: "{"address": "[email protected]", "did_you_mean": null, "is_disposable_address": false, "is_role_address": false, "is_valid": tr"
1: "ue, "mailbox_verification": "unknown", "parts": {"display_name": null, "domain": "assfuck.com", "local_part": "sdfhdd"}, "reason"
2: "": null}"

in array position 0 there is a is_validproperty. I want to see if its true or not and do some action.

everything I have tried keeps giving me errors

print(validationtext[0].is_valid)
TypeError: 'instancemethod' object has no attribute '__getitem__'

what gives?

2
  • 1
    The above json response is incomplete. Please post the compete json response. Commented Dec 28, 2018 at 2:34
  • Check this answer. It should help you. Commented Dec 28, 2018 at 2:39

2 Answers 2

2

validation.json is a function, not an attribute. If you want to get the result, you have to call the function by putting parentheses on the end, as in validationtext = validation.json().

Sign up to request clarification or add additional context in comments.

Comments

0

You didn't call the validate.json function correctly. You're missing the parenthesis: validate.json()

Just a minor oversight on your end! Happens to the best of us.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.