HTTP 401 error message when I try with private enterprise Github account - rest

I am working with python + the requests library + github access to get a hook URL.
When I try to access a hook from my personal public git repo, I get the response smoothly:
import json
import requests
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
response = requests.get("https://api.github.com/repos/josenrihernand/github-personal-repo/hooks", auth=("josenrihernand", token)).json()
print("RESPONSE: ", response) ---> IT WORKS (I get the hook url)
However, if I try with a enterprise / private github account, I get an HTTP 401 error message:
import json
import requests
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
response = requests.get("https://MY_DOMAIN/repos/ENTERPRISE_USER/REPO_PATH/hooks", auth=("ENTERPRISE_USER", token)).json()
print("RESPONSE: ", response) ---> I got a 401 error message.
I am sure that the token is ok.
What could be the root cause of that error ?
Is the get address properly formed ?
thanks a lot!

Github entreprise base URL for v3 API is :
http(s)://hostname/api/v3/
check Rest v3 API doc
I guess in your case it would be :
https://your.domain/api/v3/repos/USER/REPO/hooks

Related

GitHub - URL could not be accessed: HTTP/1.1 400 Bad Request

I am using a private repository in my project ( for example https://github.com/org/repo), and recently I am getting the below error message when I trying to run composer install.
[Composer\Downloader\TransportException]
The 'https://api.github.com/repos/org/myrepo' URL could not be accessed: HTTP/1.1 400 Bad Request
You have to update your auth.json file. Please go to Settings > Developer settings > Personal access tokens (Direct URL: https://github.com/settings/tokens) page and generate a new token and copy the token string then enable sso and authorise with your private organisation. Update your auth.json like below format.
{
"http-basic": {
"github.com": {
"username": "<YOUR-USERNAME>",
"password": "<NEW_TOKEN>"
}
}
}

How to do a source import with GitHub APIv3

background:
I am trying to build an application that will copy a public repository to the logged in account.
Now i am trying to do a source import in PostMan and i am using the following settings:
i make a PUT request to this link:
https://api.github.com/repos/{myusername}/{empty github repository}/import
with the following header:
Accept:application/vnd.github.barred-rock-preview
With this body:
{
"vcs": "git",
"vcs_url": "https://github.com/{owner of repo i want to copy}/{repo i want to copy}",
"vcs_username": "{myusername}",
"vcs_password": "{mypassword}"
}
I have read the github API for importing repositories. But i am getting the following response from the server:
{
"message": "Not Found",
"documentation_url":
"https://developer.github.com/v3/migrations/source_imports/#start-an-import"
}
Why does the server return a Not Found? How do i get this to work
It need Authentication else will get 404 Not Found
using username and password for authentication
Put URL:
https://{myusername}:{mypassword}#api.github.com/repos/{myusername}/{myreponame}/import
Request Body
{
"vcs": "git",
"vcs_url": "https://github.com/{ownerRepo}/{ownerRepoName}"
}
vcs_username and vcs_password used for remote repo not yours.

Why does the webflux client give a 404?

I'm trying to make a webflux client to connect to a remote websocket. There is an example websocket located at https://www.websocket.org/echo.html. I can have my browser make a wss request there simply by pressing "connect". In my browser developer toolbar I can then see that a succesful request is made to wss://echo.websocket.org/?encoding=text
This url is also mentioned in https://stackify.com/reactive-spring-5/ (the code there doesn't work because "input" is not defined).
However, when I try to access the same url from spring boot 2.0.0 with webflux, I get a 404:
#PostConstruct
public void run() throws URISyntaxException {
WebClient webClient = WebClient.create();
Flux<String> r =
webClient.get().uri("wss://echo.websocket.org/?encoding=text")
.retrieve()
.bodyToFlux(String.class)
.log();
r.subscribe(res -> System.out.println("ok: " + res), ex -> System.out.println(ex));
}
error:
org.springframework.web.reactive.function.client.WebClientResponseException: ClientResponse has erroneous status code: 404 Not Found
My best guess is that it somehow does not work with urls that start with "wss://". Can I change the code so that the request will be successful?
WebClient is not a WebSocket client, ReactorNettyWebSocketClient (mentioned in the article you linked) is a WebSocketClient. Please use this instead.

Read Firebase Database via HTTPS REST with error: 301 Moved Permanently

My configuration Swift 3, Vapor framework for server and Xcode 8.1
I am trying to read the contents of my firebase db by making a call to Firebase using an access_token received from Oauth 2.0, but I get error 301 Moved Permanently. What is the correct path to use in the uri of the GET request?
I suppose here is my mistake.
drop.get("it") { request in
var accesstoken = "ya2Qdkg.... and so on"
let responseFirebase = try drop.client.get("https://fir-34c2e.firebaseio.com/data/Users",
headers: ["Authorization":"Authorization: Bearer \(accesstoken)"],
query: [:])
print("FirebaseResponse_is \(responseFirebase)")
return "success"
}

POST request succeeds on box, but fails in jenkins

I have an integration test which connects to salesforce, and gets back an authentication token.
public AuthenticationResponse getAuthenticationResponse()
{
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("client_id", consumerKey);
map.add("client_secret", consumerSecret);
map.add("grant_type", GRANT_TYPE);
map.add("username", username);
map.add("password", password);
return new RestTemplate().postForObject(LOGIN_URI, map, AuthenticationResponse.class);
}
^ That's the code the test runs.
public void testConnect(){
AuthenticationResponse response = dataDotComClient.getAuthenticationResponse();
assertNotNull(response);
assertNotNull(response.getAccess_token());
}
^ And that's the test itself.
This works fine from my, and other desktops. However, it never works in jenkins, always returning a 400 status code with no real error message behind it. Is there something I have to do in Jenkins to allow post requests to external sites?
http 400 means
Bad Request - Invalid URL"
OR
"HTTP Error 400. The request hostname is invalid."
Please make sure that your destination host is reachable from jenkins machine.
Try to login to jenkins machine and run the curl/telnet command to check the connectivity.