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": "sdfhdd@assfuck.com", "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": "sdfhdd@assfuck.com", "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?

totaltool
  • 87
  • 8

2 Answers2

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().

John Gordon
  • 19,454
  • 6
  • 24
  • 42
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.

B17Z
  • 1
  • 1
  • 1