Questions? Feedback? powered by Olark live chat software
Gezintiyi Atla

Python Contoso Ads Application Cloud Service

One Code tarafından
Son güncelleştirme tarihi: 23.9.2016
Katkıda Bulunanlar:
GitHub üzerinde düzenleyin

Introduction

Flask (Micro-framework for Python) version of the Contoso Ads application in Get started with Azure Cloud Services and ASP.NET.

Prerequisites

1. Python 3.4 interpreter for Windows.

Note that only Python 3.4 and 2.7 are natively supported by Azure (Python 3.4 by default). If you prefer 2.7 or other versions, additional configuration for startup task is required.

2. Visual Studio 2013 or 2015

3. Python Tools for Visual Studio (PTVS)

4. Azure SDK Tools for VS 2013 or Azure SDK Tools for VS 2015

5. Azure Storage Account

Follow this guide to create a storage account and obtain the Access Key.

6. Azure Service Bus

Follow this guide to create a service bus and obtain the SAS key.

7. MongoDB

You may use MongoDB on Azure Virtual Machine or mLab.

Run the sample

1. Reload the project if it shows “unavailable”.

2. Modify the connection settings in WebRole1 > app > config.py.

MONGODB_SETTINGS ={
'db': 'your database name',
'host': 'your MongoDB host',
'port': port number,
'username': 'your user name',
'password': 'your password'
}

STORAGE_ACCOUNT_NAME = 'your storage account name'
STORAGE_ACCOUNT_KEY = 'storage access key'

SERVICEBUS_NAMESPACE = 'your servicebus namespace'
SERVICEBUS_ACCESS_KEYNAME = 'access key name'
SERVICEBUS_ACCESS_KEYVALUE = 'access key value'

3. Modify the connection settings in WorkerRole1 > config.py.

STORAGE_ACCOUNT_NAME = 'storage account name'
STORAGE_ACCOUNT_KEY = 'storage access key'

SERVICEBUS_NAMESPACE = 'servicebus namespace'
SERVICEBUS_ACCESS_KEYNAME = 'access key name'
SERVICEBUS_ACCESS_KEYVALUE = 'access key value'

MONGODB_NAME = 'your database name'
MONGODB_HOST = 'your MongoDB host'
MONGODB_PORT = port number
MONGODB_USERNAME = 'your user name'
MONGODB_PASSWORD = 'your password'

4. Remove the old virtual environment setting in WebRole1.

5. Add a new virtual environment in WebRole1.

6. Uncheck “Download and install packages” because we need to add some wheel files to local disk.

7. Repeat step 2 - 6 for WorkerRole1.

8. Find the .whl files in bin folder under WorkerRole1.

9. Create a bin folder in WorkerRole1 env folder and copy the .whl files to bin.

10. Repeat step 8 - 9 for WebRole1.

11. Run Install from requirements.txt for both virtual env.

12. To debug a particular role, right click on the role name and click "Set as StartUp Project".

Publish to Azure

You may follow this guide to publish the application to Azure Cloud Service.

Additional Information

1. We use wheels to install cffi, cryptograpy and Pillow library, because in Python 3.4 normal pip install for these libraries may fail and return error "Unable to find vcvarsall.bat". If your can successfully install all references just by defining the name in requirements, you may safely skip above step 8 - 10.

2. Startup and Runtime task logs are located in the C:\Resources\Directory{role}\LogFiles folder in the Cloud Service instance. Check ConfigureCloudService.txt if any library in requirements.txt is not successfully installed. Check LaunchWorker.err.txt for WorkerRole runtime errors.