我正在尝试通过python在C:\ Users \ WilsonNg \ Documents \ Internship中运行文件(asana_get_user.py)。
但是,当我运行它时,出现属性错误:
错误消息
但是,由于某些原因,此代码完成后还会发生另一个异常错误:
异常错误
因此它打开了同一文件夹中的另一个文件(email.py),并创建了异常错误。
关于为什么引用我的email.py文件的任何想法?
asana_get_user.py
import asana
# replace with your personal access token.
personal_access_token = '0/2c...'
# Construct an Asana client
client = asana.Client.access_token(personal_access_token)
# Set things up to send the name of this script to us to show that you succeeded! This is optional.
client.options['client_name'] = "hello_world_python"
# Get your user info
me = client.users.me()
# Print out your information
print ("Hello world! " + "My name is " + me['name'] + " and I my primary Asana workspace is " + me['workspaces'][0]['name'] + ".")
email.py
def create_message(sender, to, subject, message_text):
"""Create a message for an email.
Args:
sender: Email address of the sender.
to: Email address of the receiver.
subject: The subject of the email message.
message_text: The text of the email message.
Returns:
An object containing a base64url encoded email object.
"""
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string())}
def send_message(service, user_id, message):
"""Send an email message.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. The special value "me"
can be used to indicate the authenticated user.
message: Message to be sent.
Returns:
Sent Message.
"""
try:
message = (service.users().messages().send(userId=user_id, body=message)
.execute())
print ('Message Id: %s' % message['id'])
return message
except (errors.HttpError, error):
print ('An error occurred: %s' % error)
subject = "This is a test subject"
message = "This is a test content"
sent_to = "test@test.com"
sender = "test@test.com"
sending_msg = create_message(sender,sent_to,subject,message)
send_message()
答案 0 :(得分:0)
请在email.py
之前以if __name__ == '__main__':
的身份登录subject = "This is a test subject"
。
email.py
在调用import asana
时正在运行。
if __name__ == '__main__':
subject = "This is a test subject"
message = "This is a test content"
sent_to = "test@test.com"
sender = "test@test.com"
sending_msg = create_message(sender,sent_to,subject,message)
send_message()
详细了解here。