Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

HOWTO - Get past Bitbucket error from PowerShell GET call.

John Brumbelow July 26, 2019

Please help us get past a Bitbuckt error.
We are trying to use PowerShell to get individual files from our Bitbucket repository with the following script:

$username = "MyId@MyPlace.com"
$password = "MyPwd"
$csSource = "https://bitbucket.org/MyCompany/MyRepo/SomeSubFolder/SoDeeperSubFolder/MyFile.html"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$response = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri $csSource -Method Get

When we run this, we get this error:


Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel.
At line:1 char:13
+ $response = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand


We have also tried this variation:


$username = "MyId@MyPlace.com"
$password = "MyPwd"
$csSource = "https://bitbucket.org/MyCompany/MyRepo/SomeSubFolder/SoDeeperSubFolder"
$credential = New-Object System.Management.Automation.PSCredential($username, (ConvertTo-SecureString $password -AsPlainText -Force))
$destination = "C:\MyFolder\MySubFolder\MyFile.CHK.html"
$response = Invoke-WebRequest $csSource -Credential $credential -OutFile (Join-Path -Path $destination -ChildPath "MyFile.html")

And we get the same error.

1 answer

0 votes
John Brumbelow July 30, 2019

I added the following logic and it gets past the error:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 

I'm very disappointed that no one helped with this.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events