я класс, который предназначен, чтобы захватить имя пользователя и его письмо от Git обязуется:Неверный тип переменных данных?
class BitbucketData(object):
def get_user_name(self):
proc = subprocess.Popen("git --no-pager show -s --format='%an'", stdout=subprocess.PIPE)
committer_name = proc.stdout.read()
if committer_name:
return committer_name
def get_user_email(self):
proc = subprocess.Popen("git --no-pager show -s --format='%aE'", stdout=subprocess.PIPE)
committer_email = proc.stdout.read()
if committer_email:
return committer_email
Он используется затем для отправки уведомлений для пользователей (Дно рабочей версии - без переменных - все sender
и receiver
набор данных в явном виде , а не в переменных - они прокомментировали здесь):
class Services(object):
def sendmail(self, event):
repo = BitbucketData()
#to_address = repo.get_user_email()
#to_address = '[email protected]'
#to_name = repo.get_user_name()
#to_name = 'Test user'
subject = 'Bamboo build and deploy ready'
sender = 'Bamboo agent <[email protected]>'
text_subtype = 'plain'
message = """
Hello, {}.
Your build ready.
Link to scenario: URL
Link to build and deploy results: {})
""".format('Test user', os.environ['bamboo_resultsUrl'])
msg = MIMEText(message, text_subtype)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = 'Test user <[email protected]>'
smtpconnect = smtplib.SMTP('outlook.office365.com', 587)
smtpconnect.set_debuglevel(1)
smtpconnect.starttls()
smtpconnect.login('[email protected]', 'password')
smtpconnect.sendmail('[email protected]', '[email protected]', msg.as_string())
smtpconnect.quit()
print('Mail sent')
print(repo.get_user_email())
Проблема - если я использую данные из переменных (например to_address = '[email protected]'
или с помощью BitbucketData()
класса с to_address = repo.get_user_email()
- я получил ошибку от Office365 сервер:
... reply: '250 2.1.0 Sender OK\r\n' reply: retcode (250); Msg: 2.1.0 Sender OK send: "rcpt TO:<'[email protected]'>\r\n" reply: '501 5.1.3 Invalid address\r\n' reply: retcode (501); Msg: 5.1.3 Invalid address ... File "C:\Python27\lib\smtplib.py", line 742, in sendmail raise SMTPRecipientsRefused(senderrs) smtplib.SMTPRecipientsRefused: {"'[email protected]'\n": (501, '5.1.3 Invalid address')}
При использовании переменных код выглядит следующий:
class Services(object):
def sendmail(self, event):
repo = BitbucketData()
to_address = repo.get_user_email()
#to_address = '[email protected]'
to_name = repo.get_user_name()
#to_name = 'Test user'
from_address = '[email protected]'
subject = 'Bamboo build and deploy ready'
sender = 'Bamboo agent <[email protected]>'
text_subtype = 'plain'
message = """
Hello, {}.
Your build ready.
Link to scenario: URL
Link to build and deploy results: {})
""".format(to_name, os.environ['bamboo_resultsUrl'])
msg = MIMEText(message, text_subtype)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = to_name
smtpconnect = smtplib.SMTP('outlook.office365.com', 587)
smtpconnect.set_debuglevel(1)
smtpconnect.starttls()
smtpconnect.login('[email protected]', 'password')
smtpconnect.sendmail(from_address, to_address, msg.as_string())
smtpconnect.quit()
print('Mail sent')
print(repo.get_user_email())
Что я (или Microsoft SMTP ...) здесь делаю неправильно?
UPD
def sendmail(self, event):
repo = BitbucketData()
print(repr(repo.get_user_email()))
...
дает мне:
... Creating new AutoEnv config "'[email protected]'\n" send: 'ehlo pc-user.kyiv.domain.net\r\n' ...
Вы можете печатать и обновлять 'print (repr (repo.get_user_email()))' в вопросе? –
Вы заметили, что '' '[email protected]' \ n "'из вашего кода ошибки является двойной завернутой строкой? Это значение фактически содержит кавычки и символ новой строки, поэтому он, вероятно, не является допустимым адресом (если код ошибки не добавил дополнительные символы). – SuperBiasedMan
@SuperBiasedMan yup, я видел это - но не могу понять, откуда появляется «»: - | – setevoy