def get_recommend_from_cosmos(database, commands, recommend_type, error_info, totalcount_threshold, ratio_threshold, top_num=50): if len(commands) == 2: recommendation_container = database.create_container_if_not_exists( id=os.environ["Recommendation_Container_2"], partition_key=PartitionKey(path="/command")) command_str = commands[-2] + "|" + commands[-1] else: recommendation_container = database.create_container_if_not_exists( id=os.environ["Recommendation_Container"], partition_key=PartitionKey(path="/command")) command_str = commands[-1] query = generated_query_kql(command_str, recommend_type, error_info) query_items = list( recommendation_container.query_items( query=query, enable_cross_partition_query=True)) result = [] for item in query_items: if item['totalCount'] < totalcount_threshold: continue if item and 'nextCommand' in item: for command_info in item['nextCommand']: # The items in 'nextCommand' have been sorted according to frequency of occurrence command_info['ratio'] = float( (int(command_info['count']) / int(item['totalCount']))) if command_info['ratio'] * 100 < ratio_threshold: break if error_info: command_info['type'] = RecommendType.Solution else: command_info['type'] = RecommendType.Command # Commands inputed by this user do not participate in recommendations for Command scenario if command_info['command'] in commands: continue command_info['usage_condition'] = get_usage_condition( command_info['ratio']) command_info['source'] = RecommendationSource.OfflineCaculation result.append(command_info) # Sort the calculated offline data according to the usage ratio and take the top n data if result: result = sorted(result, key=lambda x: x['ratio'], reverse=True) return result[0:top_num]
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') id = str(req.route_params.get('id')) if id: endpoint = "https://localhost:8081" key = os.environ['key'] client = CosmosClient(endpoint, key) database_name = 'AzureDatabase' database = client.create_database_if_not_exists(id=database_name) container_name = 'DishesContainer' container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/name"), offer_throughput=400) query = "SELECT * FROM ALL" items = list( container.query_items(query=query, enable_cross_partition_query=True)) for item in items: if (str(item['id']) == id): container.delete_item(item, item['name']) return func.HttpResponse(f"Deleted dish having {id}!") return func.HttpResponse("Element not found", status_code=404) else: return func.HttpResponse("Please pass a dish ID", status_code=400)
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') con = 0 try: req_body = req.get_json() name = req_body['name'] dish = req_body['dish'] veg = req_body['vegetarian'] vegen = req_body['vegan'] except: pass else: endpoint = "https://localhost:8081" key = os.environ['key'] client = CosmosClient(endpoint, key) database_name = 'AzureDatabase' database = client.create_database_if_not_exists(id=database_name) container_name = 'DishesContainer' container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/name"), offer_throughput=400) dish = new_item(name, dish, veg, vegen) items = [dish] for item in items: container.create_item(body=item) con = 1 if (con == 1): return func.HttpResponse(f"Dish feeded") else: return func.HttpResponse( "Please pass a valid query in the request body", status_code=400)
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') name = req.params.get('name') if not name: try: req_body = req.get_json() except ValueError: pass else: name = req_body.get('name') if name: return func.HttpResponse( f"Hello, {name}. This HTTP triggered function executed successfully." ) else: endpoint = "https://pythondemo.documents.azure.com:443/" key = 'Qyxm4LRY5vEh41KzNz6HMFzqCbzLZDorySjzm1sZ26QSVduiEUuLOl96y5YA7jSemG7NLPIimdEQXiRWeSU4qA==' client = CosmosClient(endpoint, key) database_name = 'pythondemo' database = client.create_database_if_not_exists(id=database_name) container_name = 'container1' container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/id"), offer_throughput=400) query = 'SELECT * FROM c WHERE c.name = "sneha"' items = list( container.query_items(query=query, enable_cross_partition_query=True)) print("bla bla" + str(items)) return func.HttpResponse("success", status_code=200)
def hello(request): context = {'items': [], 'status_text': 'ok', 'created': {}} client = CosmosClient(endpoint, key) database = client.create_database_if_not_exists(id=database_name) container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/name"), offer_throughput=400) query = "SELECT * FROM c items" items = list( container.query_items(query=query, enable_cross_partition_query=True)) context['items'] = items if request.method == 'GET': return render(request, template_name='index.html', context=context) elif request.method == 'POST': picture = request.FILES.get('picture') item = push_image(picture, request.POST['name'], request.POST['age'], request.POST['category']) container.upsert_item(body=item) items.append(item) context['items'] = items return render(request, template_name='index.html', context=context) elif request.method == 'PUT': print(request.PUT) pass else: pass return render(request, template_name='index.html', context=context)
def run_sample(): AUTH_URI = os.environ.get("ACCOUNT_URI") AUTH_KEY = os.environ.get("ACCOUNT_KEY") DATABASE_ID = "testdocumentmanagementdb" CONTAINER_ID = "testdocumentmanagementcollection" client = CosmosClient(AUTH_URI, AUTH_KEY) database = client.create_database(id=DATABASE_ID) partition_key = PartitionKey(path="/purchase_order_number") try: container = database.create_container(id=CONTAINER_ID, partition_key=partition_key) print(f'Container with id "{CONTAINER_ID}"" created') except HTTPFailure as e: if e.status_code == 409: print(f"Container with id {CONTAINER_ID} already exists") container = database.get_container(container=CONTAINER_ID) else: raise DocumentManagement.create_documents(container) DocumentManagement.read_document(container, "SalesOrder1") DocumentManagement.read_documents(container) client.delete_database(database=DATABASE_ID) print("\nrun_sample done")
def create_container_if_does_not_exists(self, container_name=None, partition_key_path=None, **options): """ Create a container if it does not exists already :param container_name: name of the container :param partition_key_path: path of partition key in the data that you will commit. eg data --> {'name': 'sajal', 'last_name': 'john'}, if 'name' is going to be your partition key, pass partition_key_path = "/name" or "name". Partition key should be a fairly unique value and should not be imbalanced which will create performance issues. :param options: :return: """ partition_key_path = partition_key_path or self.options_.get('partition_key_path') \ or options.get('partition_key_path') if isinstance(partition_key_path, str) and partition_key_path[0] != "/": partition_key_path = "/" + partition_key_path self.container_name = container_name if container_name else self.container_name self.container_client = self.database_client\ .create_container_if_not_exists( id=self.container_name, partition_key=PartitionKey(path=partition_key_path or self.options_.get('partition_key_path')), **options )
def default_actions(host, key, database_name, container_name, partition_name): '''Connect naar Azure, maakt database aan en maakt container aan Keyword Arguments: host(string) -- Host waar je naartoe verbindt. key(string) -- Geheime sleutel van de database. database_name(string) -- Naam van database die aangemaakt moet worden. container_name(string) -- Naam van container die aangemaakt moet worden. partition_name(string) -- Naam van partitie_key die bij de container hoort. Returns: container -- Container waar je vervolgens naartoe kan schrijven. ''' # Connecten naar Azure client = cosmos_client.CosmosClient(host, {'masterKey': key}) # Maken en ophalen van database en container client.create_database_if_not_exists(id=database_name) database = client.get_database_client(database_name) database.create_container_if_not_exists( container_name, partition_key=PartitionKey(path=partition_name)) container = database.get_container_client(container_name) return container
def cosdb(db, ctr, prtn): # Connect to a CosmosDB database and container # Setup Logging logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) # Initialize the Cosmos client endpoint = os.environ.get("OURO_DOCUMENTS_ENDPOINT", "SET OURO_DOCUMENTS_ENDPOINT IN ENVIRONMENT") key = os.environ.get("OURO_DOCUMENTS_KEY", "SET OURO_DOCUMENTS_KEY IN ENVIRONMENT") client = CosmosClient(endpoint, key) database = client.create_database_if_not_exists(id=db) # Connect to the daily_indicators container try: container = database.create_container_if_not_exists( id=ctr, partition_key=PartitionKey(path=prtn), offer_throughput=400) logging.info('Azure-Cosmos client initialized; connected to ' + db + '.' + ctr + ' at ' + endpoint) return container except Exception as ex: logging.critical('Unable to create connection to ' + db + '.' + ctr + ' at ' + endpoint) logging.critical(ex) quit(-1)
def main(req: func.HttpRequest) -> func.HttpResponse: URL = "https://junctionx.documents.azure.com:443/" KEY = "BCw9nhNiTSl9ndUokCw6uHhzZSDgsSGoMjPUa0Ech6E9yiuGKCrsswFIXRatcguQYcNLnYdhFPWPhuaRtLfoxg==" DATABASE_NAME = "MitoSoftCorp" CONTAINER_NAME = "workType" client = CosmosClient(URL, credential=KEY) work_type = req.params.get("work_type") try: database = client.create_database(DATABASE_NAME) except exceptions.CosmosResourceExistsError: database = client.get_database_client(DATABASE_NAME) try: container = database.create_container( id=CONTAINER_NAME, partition_key=PartitionKey(path="/name")) except exceptions.CosmosResourceExistsError: container = database.get_container_client(CONTAINER_NAME) user_list = [] for item in container.query_items( query='SELECT * FROM {} w WHERE w.work_type = "{}"'.format( CONTAINER_NAME, work_type), enable_cross_partition_query=True): user_list.append(item.get("user_id")) return_data = dict(id=user_list) return func.HttpResponse(json.dumps(return_data), headers={"Content-Type": "application/json"}, status_code=200)
def add_to_db(message): # Initialize the Cosmos client endpoint = 'https://talkingdb.documents.azure.com:443/' key = 'nL5f0ZJPKLwxSaKigi2BNlk9eVn5jtZCeoFIg85TeCC73vkBCy2BctEY27YDMCh8B4UXg8Gq1GvrNBeltrNYgg==' #create cosmos client client = CosmosClient(endpoint, key) try: # Create a database database_name = 'tcdb' database = client.create_database_if_not_exists(id=database_name) except exceptions.CosmosResourceExistsError: pass # Create a container # Using a good partition key improves the performance of database operations. try: container_name = 'c1' container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/messages"), offer_throughput=400) except exceptions.CosmosResourceExistsError: pass container.create_item(body=message)
def main(req: func.HttpRequest) -> func.HttpResponse: # Initialize the Cosmos client endpoint = "https://parking-spots.documents.azure.com:443/" key = 'c9av0FP6xBrnz7XNUdBNIUFdCuo1IvE3H2SWvvB8Pxo92ALKzfW2gDXxgQlBlyUJtLDiJSZK6Ew8YO8yPNepnA==' client = CosmosClient(endpoint, key) # Select database database_name = 'Parking-Data' database = client.create_database_if_not_exists(id=database_name) # Select container container_name = 'Items' container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/slots"), offer_throughput=400 ) # Query slots using SQL query = "SELECT * FROM c" items = list(container.query_items( query=query, enable_cross_partition_query=True )) return func.HttpResponse(json.dumps(items))
def get_item(request, pk, name): context = {'item': [], 'status_text': 'ok', 'created': {}} client = CosmosClient(endpoint, key) database = client.create_database_if_not_exists(id=database_name) container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/name"), offer_throughput=400) print(request) if request.method == "DELETE": print('delete') try: container.delete_item(item=pk, partition_key=name) except CosmosResourceNotFoundError: return HttpResponse("Resource not Found") return redirect('http://127.0.0.1:8000') # return render(request, template_name='index.html', context=context) elif request.method == 'POST': item = { 'id': request.POST.get('id'), 'name': request.POST.get('name'), 'age': request.POST.get('age'), 'category': request.POST.get('category'), 'picture': request.POST.get('picture') } # picture = request.FILES.get('picture') # item = push_image(picture, request.POST['name'], request.POST['age'], request.POST['category']) container.replace_item(item=item['id'], body=item) context['item'] = [item] return render(request, template_name='index.html', context=context) else: item = container.read_item(pk, partition_key=name) context['item'] = item return render(request, template_name='index.html', context=context)
def __init___(image_name,section,label): # Initialize the Cosmos client endpoint = os.getenv('AZURE_DATABASE_URL') key = os.getenv('AZURE_DATABASE_KEY') # <create_cosmos_client> client = CosmosClient(endpoint, key) # </create_cosmos_client> # Create a database # <create_database_if_not_exists> database_name = 'satlabelingdb' database = client.create_database_if_not_exists(id=database_name) # </create_database_if_not_exists> # Create a container # Using a good partition key improves the performance of database operations. # <create_container_if_not_exists> container_name = 'labelinfo' container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/info"), offer_throughput=400 ) image_info = get_image_info_json(image_name,section,label) read_item = container.read_item(item=image_name, partition_key=key) if read_item: container.replace_item(item=read_item, boby=image_info) else: container.create_item(body=image_info) print("updated datbase")
def test_default_account_consistency(self): # These tests use the emulator, which has a default consistency of "Session" # If your account has a different level of consistency, make sure it's not the same as the custom_level below client = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey) database_account = client.get_database_account() account_consistency_level = database_account.ConsistencyPolicy[ "defaultConsistencyLevel"] self.assertEqual(account_consistency_level, "Session") # Testing the session token logic works without user passing in Session explicitly database = client.create_database(DATABASE_ID) container = database.create_container( id=CONTAINER_ID, partition_key=PartitionKey(path="/id")) container.create_item(body=get_test_item()) session_token = client.client_connection.last_response_headers[ http_constants.CookieHeaders.SessionToken] item2 = get_test_item() container.create_item(body=item2) session_token2 = client.client_connection.last_response_headers[ http_constants.CookieHeaders.SessionToken] # Check Session token is being updated to reflect new item created self.assertNotEqual(session_token, session_token2) container.read_item(item=item2.get("id"), partition_key=item2.get("id")) read_session_token = client.client_connection.last_response_headers[ http_constants.CookieHeaders.SessionToken] # Check Session token remains the same for read operation as with previous create item operation self.assertEqual(session_token2, read_session_token) client.delete_database(DATABASE_ID) # Now testing a user-defined consistency level as opposed to using the account one custom_level = "Eventual" client = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey, consistency_level=custom_level) database_account = client.get_database_account() account_consistency_level = database_account.ConsistencyPolicy[ "defaultConsistencyLevel"] # Here they're not equal, since the headers being used make the client use a different level of consistency self.assertNotEqual( client.client_connection.default_headers[ http_constants.HttpHeaders.ConsistencyLevel], account_consistency_level) # Test for failure when trying to set consistency to higher level than account level custom_level = "Strong" client = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey, consistency_level=custom_level) try: client.create_database(DATABASE_ID) except exceptions.CosmosHttpResponseError as e: self.assertEqual(e.status_code, http_constants.StatusCodes.BAD_REQUEST)
def __init__(self, blob_service: BlobServiceClient, db: DatabaseProxy): try: self.blob_container = blob_service.create_container("images") except ResourceExistsError as exc: self.blob_container = blob_service.get_container_client( container="images") self.cosmos_container = db.create_container_if_not_exists( id="images", partition_key=PartitionKey(path="/image/path"))
def __init__(self): self.client = CosmosClient(url=connection_key, credential=master_key) self.db = self.client.create_database_if_not_exists( id=CONSTANTS['COSMOS']['DATABASE']) self.container = self.db.create_container_if_not_exists( id=CONSTANTS['COSMOS']['CONTAINER'], partition_key=PartitionKey(path="/_partitionKey"), offer_throughput=400)
def create_container(database, container_name): try: container = database.create_container( id=container_name, partition_key=PartitionKey(path="/league")) except exceptions.CosmosResourceExistsError: container = database.get_container_client(container_name) except exceptions.CosmosHttpResponseError: raise return container
def __init__(self, endpoint, key, database_name, container_name): self.key = key self.database_name = database_name client = CosmosClient(endpoint, key) self.database = client.create_database_if_not_exists(id=database_name) self.container = self.database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/id"), offer_throughput=400)
def main(req: func.HttpRequest) -> func.HttpResponse: ##SQL conn = pyodbc.connect('Driver={SQL Server};' 'Server=.;' 'Database=StackOverflow;' 'Trusted_Connection=yes;') cursor = conn.cursor() cursor.execute("""SELECT (SELECT CAST([id] AS varchar(50)) AS [id] ,[AcceptedAnswerId] ,[AnswerCount] ,[Body] ,[ClosedDate] ,[CommentCount] ,[CommunityOwnedDate] ,[CreationDate] ,[FavoriteCount] ,[LastActivityDate] ,[LastEditDate] ,[LastEditorDisplayName] ,[LastEditorUserId] ,[OwnerUserId] ,[ParentId] ,[PostTypeId] ,[Score] ,[Tags] ,[Title] ,[ViewCount] FOR JSON PATH, WITHOUT_ARRAY_WRAPPER) AS Result FROM [StackOverflow].[dbo].[Posts] ORDER BY [id] ASC""") ##Cosmos client = CosmosClient(os.environ["ACCOUNT_URI"], os.environ["ACCOUNT_KEY"], logging_enable=False) database_name = 'StackOverflow' database = client.create_database_if_not_exists(id=database_name) container_name = 'Posts' container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/id"), offer_throughput=400, analytical_storage_ttl=-1 ) i = 0 startTime = datetime.now() for row in cursor: obj = json.loads(row.Result) obj["ExtractionDate"] = datetime.now().isoformat() container.create_item(obj,False) i=i+1 if i%100==0: logging.warning("{} elapse for the last 100 Posts insertions".format(datetime.now()-startTime)) startTime = datetime.now() return func.HttpResponse( "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", status_code=200 )
def restart(): client.delete_database(database_name) database = client.create_database_if_not_exists(id=database_name) container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/grade"), offer_throughput=400) return jsonify({True}) """
def container(): db = database() default_container_name = 'FastApiContainer' container = db.create_container_if_not_exists( id=default_container_name, partition_key=PartitionKey(path='/id'), offer_throughput=400) return container
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') try: req_body = req.get_json() name = req_body['name'] email = req_body['email'] username = req_body['username'] password = req_body['password'] admin = req_body['admin'] adminpass = req_body['adminpass'] except: return func.HttpResponse( "Please pass all details name, email, username, password, admin, adminpass in the request body", status_code=400) if (str(admin + adminpass) != "abhishek0220createuser"): return func.HttpResponse("Authentication Failed", status_code=401) try: endpoint = "https://*****:*****@binarybeasts.com', to_emails=email, subject='Welcome to QR Based Inventory', html_content= 'Welcome to QR Based Inventory web application developed by Binary Beasts. Note down your Credientials - <br>Username : <strong>' + username + '</strong><br>Password : <strong>' + password + '</strong><br>Link : <strong>' + link + '</strong><br><br><br>Message by - Abhishek Chaudhary<br>[email protected]' ) try: sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) response = sg.send(message) except Exception as e: print(e.message) return func.HttpResponse(f"User Added")
def main(req: func.HttpRequest) -> func.HttpResponse: try: command = get_param_str(req, 'command') if not command: return func.HttpResponse( 'Illegal parameter: please pass in the parameter "command"', status_code=400) except ValueError: return func.HttpResponse( 'Illegal parameter: the parameter "command" must be the type of string', status_code=400) try: top_num = get_param_int(req, 'top_num') except ValueError: return func.HttpResponse( 'Illegal parameter: the parameter "top_num" must be the type of int', status_code=400) try: recommend_type = get_param_int(req, 'type') except ValueError: return func.HttpResponse( 'Illegal parameter: the parameter "type" must be the type of int', status_code=400) client = CosmosClient(os.environ["CosmosDB_Endpoint"], os.environ["CosmosDB_Key"]) database = client.create_database_if_not_exists(id="cli-recommendation") container = database.create_container_if_not_exists( id="recommendation-without-arguments", partition_key=PartitionKey(path="/command")) query = "SELECT * FROM c WHERE c.command = '{}' ".format(command) query_items = list( container.query_items(query=query, enable_cross_partition_query=True)) if not query_items: return func.HttpResponse('{}', status_code=200) result = [] for item in query_items: if item and 'nextCommand' in item: for command_info in item['nextCommand']: if not recommend_type or recommend_type == command_info['type']: command_info['ratio'] = float( (int(command_info['count']) / int(item['totalCount']))) result.append(command_info) if top_num: result = result[0:top_num] return func.HttpResponse(generate_response(data=result, status=200))
def get_cosmos_container(self, database, container_name, partition, offer_throughput=400): partition_key = PartitionKey(path=partition, kind='Hash') container = database.create_container_if_not_exists( id=container_name, partition_key=partition_key, offer_throughput=offer_throughput) return container
def __init__(self, db, container_name, partition_key): self.db = db self.container_name = container_name self.partition_key = partition_key try: self.container = db.create_container( id=container_name, partition_key=PartitionKey(path='/{}'.format(partition_key))) except CosmosResourceExistsError: print('Container already exists, use the existing container.') self.container = db.get_container_client(container_name)
def __init__(self): load_dotenv() _endpoint = os.getenv('ENDPOINT') _key = os.getenv('KEY') _db_name = os.getenv('DATABASE_NAME') _lemons_container_name = os.getenv('CONTAINER_LEMONS_NAME') _makers_models_container_name = os.getenv('CONTAINER_MAKERS_NAME') self.lemons_pk = os.getenv('CONTAINER_LEMONS_PARTITIONKEY') self.makers_models_pk = os.getenv('CONTAINER_MAKERS_PARTITIONKEY') client = CosmosClient(_endpoint, _key) db = client.create_database_if_not_exists(id=_db_name) self.lemons_container = db.create_container_if_not_exists( id=_lemons_container_name, partition_key=PartitionKey(path=self.lemons_pk)) self.makers_models_container = db.create_container_if_not_exists( id=_makers_models_container_name, partition_key=PartitionKey(path=self.makers_models_pk))
def __init__(self): endpoint = "https://moneysquare.documents.azure.com:443/" key = 'weo3vRIX2wSInZ1u4CYP18W2k55p2CZdYjnCyTo1CKpVuq3f8Ebk6SqCisW2O1J6znN49AF4vTkvCMKThcYdOQ==' self.client = CosmosClient(endpoint, key) database_name = 'MoneySquareDatabase' database = self.client.create_database_if_not_exists(id=database_name) container_name = 'GoalContainer' self.container = database.create_container_if_not_exists( id=container_name, partition_key=PartitionKey(path="/id"), offer_throughput=400) super().__init__()
def get_cosmosdb_container(self, container_name, database, partition_key): container = None try: container = database.create_container( id=container_name, partition_key=PartitionKey(path=partition_key)) except exceptions.CosmosResourceExistsError: container = database.get_container_client(container_name) except exceptions.CosmosHttpResponseError: raise finally: if container is not None: return container
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') try: req_body = req.get_json() username = req_body['username'] code = req_body['code'] except: return func.HttpResponse("Please pass username in the request body", status_code=400) try: endpoint = "https://*****:*****@binarybeasts.com', to_emails=email, subject='Password Reset', html_content= 'OTP to reset password of your QR Based Inventory account <strong>' + code + '</strong>') try: sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) response = sg.send(message) print(response.status_code) print(response.body) print(response.headers) except Exception as e: print(e.message) return func.HttpResponse(f"Send") else: return func.HttpResponse("Username not found", status_code=400)