Я пытаюсь создать скрипт Python, который будет сканировать файл проекта Azure DevOps и загружать его локально. Однако я столкнулся с проблемой, из-за которой запрос на загрузку файла не работает, поскольку запрос является «опасным».
Ошибка:< /p>
Failed to clone file 'mkdocs.yml' from repository 'crawl-ado'
Response: 400
{"$id":"1","innerException":null,"message":"A potentially dangerous Request.Path value
was detected from the client (:).","typeName":"System.Web.HttpException,
System.Web","typeKey":"HttpException","errorCode":0,"eventId":0}
Моя текущая стратегия — получить список репозиториев через токен Azure PAT и сделать запрос json, чтобы проверить, являются ли эти репозитории содержать файл. Если да, я хочу создать новый файл и загрузить его в свою локальную среду. Что-то не так с моей логикой, или я пытаюсь сделать что-то подобное неправильно? Заранее спасибо!
crawl.py:
import os
import requests
import base64
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
# Replace these variables with your Azure DevOps organization, project, and personal access token (PAT)
organization = "https://dev.azure.com/MYORG"
project = os.getenv('PROJECT')
pat = os.getenv('PAT')
file_path = "mkdocs.yml" # Replace with the path to the specific file you want to clone
# Check to see if PROJECT & PAT are set.
if not project:
print("Please set the PROJECT environment variable!")
exit(1)
if not pat:
print("Please set the PAT environment variable!")
exit(1)
else:
print("PAT is set!")
print("***************************************")
# Create a connection to the Azure DevOps organization
credentials = BasicAuthentication('', pat)
connection = Connection(base_url=organization, creds=credentials)
# Get a client for the Git service
git_client = connection.clients.get_git_client()
# Get a list of repositories in the project
repos = git_client.get_repositories(project=project)
# Store the repository names in an array
repo_names = [repo.name for repo in repos]
# Display the repository names and download the file from each repository
print("Repositories in project '{}':".format(project))
for repo_name in repo_names:
print(repo_name)
url = f'https://dev.azure.com/{organization}/{p ... ersion=7.1'
headers = {
'Authorization': f'Basic {base64.b64encode(f":{pat}".encode()).decode()}'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
file_content = response.text
with open(file_path, 'w') as file:
file.write(file_content)
print(f"File '{file_path}' cloned successfully from repository '{repo_name}'")
else:
print(f"Failed to clone file '{file_path}' from repository '{repo_name}'")
print(f"Response: {response.status_code}")
print(response.text)
Подробнее здесь: https://stackoverflow.com/questions/792 ... ownload-it
Скрипт Python для сканирования проекта ADO для конкретного файла и его загрузки ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение