本文整理汇总了Python中email_validator.EmailNotValidError方法的典型用法代码示例。如果您正苦于以下问题:Python email_validator.EmailNotValidError方法的具体用法?Python email_validator.EmailNotValidError怎么用?Python email_validator.EmailNotValidError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email_validator
的用法示例。
在下文中一共展示了email_validator.EmailNotValidError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_email_invalid
# 需要导入模块: import email_validator [as 别名]
# 或者: from email_validator import EmailNotValidError [as 别名]
def test_email_invalid():
with pytest.raises(EmailNotValidError):
EmailNotification('foo')
示例2: is_valid_email_address
# 需要导入模块: import email_validator [as 别名]
# 或者: from email_validator import EmailNotValidError [as 别名]
def is_valid_email_address(email_address):
"""
Check that the string specified appears to be a valid email address.
:param str email_address: The email address to validate.
:return: Whether the email address appears to be valid or not.
:rtype: bool
"""
if email_address is None:
return False
try:
email_validator.validate_email(email_address, allow_empty_local=False, check_deliverability=False)
except email_validator.EmailNotValidError:
return False
return True
示例3: validate_email
# 需要导入模块: import email_validator [as 别名]
# 或者: from email_validator import EmailNotValidError [as 别名]
def validate_email(email):
try:
return email_validator.validate_email(email)["email"]
except email_validator.EmailNotValidError as e:
raise EmailNotValidException(str(e))
示例4: check_value
# 需要导入模块: import email_validator [as 别名]
# 或者: from email_validator import EmailNotValidError [as 别名]
def check_value(self, value):
try:
validate_email(value,
allow_smtputf8=self.allow_smtputf8,
check_deliverability=self.check_deliverability,
allow_empty_local=self.allow_empty_local)
return True
except EmailNotValidError:
return False
示例5: get_mfa
# 需要导入模块: import email_validator [as 别名]
# 或者: from email_validator import EmailNotValidError [as 别名]
def get_mfa(self, username):
try:
validate_email(username)
accountType = 2 # email
except EmailNotValidError as _e:
accountType = 1 # phone
response = requests.get(self._urls.get_mfa(username, str(accountType), str(self._did), str(5), str(1)), headers=self._headers)
示例6: validate_email
# 需要导入模块: import email_validator [as 别名]
# 或者: from email_validator import EmailNotValidError [as 别名]
def validate_email(value: Union[str]) -> Tuple[str, str]:
"""
Brutally simple email address validation. Note unlike most email address validation
* raw ip address (literal) domain parts are not allowed.
* "John Doe <local_part@domain.com>" style "pretty" email addresses are processed
* the local part check is extremely basic. This raises the possibility of unicode spoofing, but no better
solution is really possible.
* spaces are striped from the beginning and end of addresses but no error is raised
See RFC 5322 but treat it with suspicion, there seems to exist no universally acknowledged test for a valid email!
"""
if email_validator is None:
import_email_validator()
m = pretty_email_regex.fullmatch(value)
name: Optional[str] = None
if m:
name, value = m.groups()
email = value.strip()
try:
email_validator.validate_email(email, check_deliverability=False)
except email_validator.EmailNotValidError as e:
raise errors.EmailError() from e
at_index = email.index('@')
local_part = email[:at_index] # RFC 5321, local part must be case-sensitive.
global_part = email[at_index:].lower()
return name or local_part, local_part + global_part
示例7: login
# 需要导入模块: import email_validator [as 别名]
# 或者: from email_validator import EmailNotValidError [as 别名]
def login(self, username='', password='', device_name='', mfa=''):
'''
Login with email or phone number
phone numbers must be a str in the following form
US '+1-XXXXXXX'
CH '+86-XXXXXXXXXXX'
'''
if not username or not password:
raise ValueError('username or password is empty')
# with webull md5 hash salted
password = ('wl_app-a&b@!423^' + password).encode('utf-8')
md5_hash = hashlib.md5(password)
try:
validate_email(username)
accountType = 2 # email
except EmailNotValidError as _e:
accountType = 1 # phone
if device_name == '' :
device_name = 'default_string'
data = {
'account': username,
'accountType': accountType,
'deviceId': self._did,
'deviceName': device_name,
'grade': 1,
'pwd': md5_hash.hexdigest(),
'regionId': 1
}
if mfa != '' :
data['extInfo'] = {'verificationCode': mfa}
headers = self.build_req_headers()
else :
headers = self._headers
response = requests.post(self._urls.login(), json=data, headers=headers)
result = response.json()
if 'accessToken' in result :
self._access_token = result['accessToken']
self._refresh_token = result['refreshToken']
self._token_expire = result['tokenExpireTime']
self._uuid = result['uuid']
self._account_id = self.get_account_id()
return result