How to grammatically enable the issue tracker of a given repository I own through the GitHub API? - python-3.x

I have bunch of repository forks, and I would like to enable all their issue trackers. I am not sure why, GitHub comes with them disabled by default and I had forgot to enable them when forking.
Now would be too much work enable their issues tracker one by one, then, I though I could write a program to do this. For now, I managef to get a list of all repositories I own, with the following code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import shlex
import json
import subprocess
current_directory = os.path.dirname( os.path.realpath(__file__) )
print( 'directory walk %s', current_directory )
token = "Authorization: token mynicetoken102312312541230240021470300250230"
user_name = "myusername"
def run_command(absolute_path, command_name):
command = shlex.split( command_name )
print( 'command: %s' % command )
command_line_interface = subprocess.Popen( command, stdout=subprocess.PIPE, cwd=absolute_path )
output = command_line_interface.communicate()[0]
print( "\n%s" % output.decode('utf-8') )
return output
def main():
result = run_command( current_directory, "curl -H '%s' https://api.github.com/users/%s/repos" % ( token, user_name ) )
result_json = json.loads( result.decode('utf-8') )
for repository_data in result_json:
repository_full_name = repository_data['full_name']
print( "Processing{:s}".format( repository_full_name ) )
# Now, what do?
run_command( current_directory, "curl -H '%s' https://api.github.com/%s/misterX" % ( token, repository_full_name ) )
if __name__ == "__main__": main()
I think the only thing missing is the complete the last line:
# Now, what do?
run_command( current_directory, "curl -H '%s' https://api.github.com/%s/misterX" % ( token, repository_full_name ) )
After finding How do I rename a GitHub repository via their API? I manage to build the following code:
# Now, what do?
full_command = \
r"""
curl
-H "Authorization: Token %s"
-H "Content-Type: application/json"
-H "Accept: application/json"
-X PATCH
--data '{ "has_issues": true }'
https://api.github.com/repos/:%s
""" % ( token, repository_full_name )
print( 'full_command: %s' % full_command )
run_command( current_directory, full_command )
But GitHub says:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#edit"
}
Their API page does not help much: https://developer.github.com/v3/repos/#edit
References:
How to retrieve the list of all github repositories of a person?
https://github.com/settings/tokens GitHub token with full repository access

The answer I used on How do I rename a GitHub repository via their API? was wrong. It was using https://api.github.com/repos/:owner/repo, but it should be https://api.github.com/repos/owner/repo. After fixing that, GitHub kept saying:
{
"message": "Validation Failed",
"errors": [
{
"resource": "Repository",
"code": "custom",
"field": "name",
"message": "name is too short (minimum is 1 character)"
}
],
"documentation_url": "https://developer.github.com/v3/repos/#edit"
}
Then, I added "name": "repository_name" to the json, and it worked. This is this new code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import shlex
import json
import subprocess
import shutil
"""
Iterates through all repositories from a user and enable the issue tracker.
"""
# GitHub token with full repository access
# https://github.com/settings/tokens
token = "8217398127859182039802175098213389019766"
user_name = "username"
current_directory = os.path.dirname( os.path.realpath(__file__) )
print( 'directory walk %s' % current_directory )
# The maximum count of repositories to to process when calling this batch script.
maximum_process_limit = 1000
def run_command(absolute_path, command_name):
command = shlex.split( command_name )
print( 'command: %s' % command )
command_line_interface = subprocess.Popen(
command, stdout=subprocess.PIPE, cwd=absolute_path )
output = command_line_interface.communicate()[0]
# print( "%s" % output )
# print( "\n%s" % output.decode('utf-8') )
return output
def main():
page_index = 1
while process_repositories_page( page_index ):
page_index += 1
def process_repositories_page(page_index):
global maximum_process_limit
items_per_page = 100
repositories_text = run_command( current_directory,
"curl -H '%s' https://api.github.com/users/%s/repos?per_page=%s&page=%s" % (
token, user_name, items_per_page, page_index ) )
repositories_json = json.loads( repositories_text.decode('utf-8') )
for repository_data in repositories_json:
print( "Processing repository: %s" % repository_data['full_name'] )
if maximum_process_limit <= 0: return
maximum_process_limit -= 1
full_command = \
r"""
curl
-H "Authorization: Token {token}"
-H "Content-Type: application/json"
-H "Accept: application/json"
-X PATCH
--data '{data}'
https://api.github.com/repos/{full_name}
""".format(
token=token,
data=json.dumps(
{
"name": repository_data['name'],
"has_issues": True
}
),
full_name=repository_data['full_name']
)
print( 'full_command: %s' % full_command )
result = run_command( current_directory, full_command )
print( 'result: %s' % result.decode('utf-8') )
return len( repositories_json ) == items_per_page
if __name__ == "__main__":
main()
New references:
Programmatically enable Github Pages for a repository
Escape double quotes for JSON in Python
Github API v3 doesn't show all user repositories

Related

Writing to a json file with Polish characters

I am using a JSON file to send data from an LDAP database on linux ADDC SAMBA for further processing. I fetch the data with a script written in python3. My problem is that some fields contain Polish characters that are encoded in unicode, for example "Bo\u017Cena \u017Ar\u00F3dlana" should be "Bożena Źródlana" . I would like the file to contain already decoded data so that I can read them without guessing what character is behind the unicode code.
I need to ask for help where in my code I should put something similar to a decoder so that the entire file is already saved as decoded and containing Polish special characters
my python3 code:
#! /usr/bin/python3
import os
import configparser
import getpass
import sys
import json
import ssl
import shutil
from ldap3 import Server, Connection, Tls, ALL_ATTRIBUTES
from datetime import date
# screen cleaner
os.system('clear')
# timestamp
current_datetime = str(date.today())
# load main config files
main_conf_file = "/tmp/ldap-searchlight/config/searchlight.conf"
config = configparser.RawConfigParser()
config.read(main_conf_file)
# variables
main_path = config['GLOBAL']['main_path']
conf_path = config['GLOBAL']['conf_path']
data_path = config['GLOBAL']['data_path']
arch_patch = config['GLOBAL']['arch_patch']
json_users_file = config['USERS']['json_users_file']
json_cmptrs_file = config['CMPTRS']['json_cmptrs_file']
# ldap variables
ldap_base_dn = config['GLOBAL']["ldap-base-dn"]
ldap_users = config['USERS']['ldap-users']
ldap_cmptrs = config['CMPTRS']['ldap_cmptrs']
user1_name = config['USERS']['user1-name']
user2_name = config['USERS']['user2-name']
user3_name = config['USERS']['user3-name']
user4_name = config['USERS']['user4-name']
user5_name = config['USERS']['user5-name']
# user's choice
print(
"Logujesz się jako:\n" +
" wybierz [ 1 ] dla " + user1_name + "\n" +
" wybierz [ 2 ] dla " + user2_name + "\n" +
" wybierz [ 3 ] dla " + user3_name + "\n" +
" wybierz [ 4 ] dla " + user4_name + "\n" +
" wybierz [ 5 ] dla " + user5_name + "\n"
)
input_name = input("WYBRANO: ")
if input_name == "1" :
user = config["USERS"]["ldap-user1"]
elif input_name == "2" :
user = config["USERS"]["ldap-user2"]
elif input_name == "3" :
user = config["USERS"]["ldap-user3"]
elif input_name == "4" :
user = config["USERS"]["ldap-user4"]
elif input_name == "5" :
user = config["USERS"]["ldap-user5"]
else:
print("Permission danied\n")
sys.exit(1)
password = getpass.getpass()
LDAP_HOST = config['GLOBAL']['ldap-host']
LDAP_USER = user +","+ ldap_users +","+ ldap_base_dn
LDAP_PASSWORD = password
tls_configuration = Tls(validate=ssl.CERT_NONE, version=ssl.PROTOCOL_TLSv1)
def ldap_server():
return Server(LDAP_HOST, use_ssl=True, tls=tls_configuration, get_info=ALL_ATTRIBUTES)
def ldap_connection():
server = ldap_server(),
return Connection(server, user=LDAP_USER,
password=LDAP_PASSWORD,
auto_bind=True)
# ldap users
LDAP_BASE_DN = ldap_users +","+ ldap_base_dn
LDAP_OBJECT_FILTER = '(objectclass=user)'
user_attr_list=[ \
'cn', \
'sn', \
'givenName', \
'instanceType', \
'whenCreated', \
'displayName', \
'uSNCreated', \
'name', \
'objectGUID', \
'badPwdCount', \
'codePage', \
'countryCode', \
'badPasswordTime', \
'lastLogoff', \
'lastLogon',\
'primaryGroupID', \
'objectSid', \
'accountExpires', \
'logonCount', \
'sAMAccountName', \
'sAMAccountType', \
'userPrincipalName', \
'objectCategory', \
'pwdLastSet', \
'userAccountControl', \
'lastLogonTimestamp', \
'whenChanged', \
'uSNChanged', \
'memberOf', \
'distinguishedName' ]
conn = ldap_connection()
conn.search(LDAP_BASE_DN, LDAP_OBJECT_FILTER, attributes=user_attr_list)
# output to json
json_users_data = main_path + data_path + json_users_file
data = json.loads(conn.response_to_json())
with open(json_users_data, 'w') as jsonfile:
json.dump(data, jsonfile)
# copy data to archive
json_users_arch = main_path + arch_patch + current_datetime + "_" + json_users_file
shutil.copy2(json_users_data, json_users_arch)
# ldap computers
LDAP_BASE_DN = ldap_cmptrs +","+ ldap_base_dn
LDAP_OBJECT_FILTER = '(objectclass=computer)'
cmptr_attr_list=[ \
'cn', \
'instanceType', \
'whenCreated', \
'uSNCreated', \
'name', \
'objectGUID', \
'badPwdCount', \
'codePage', \
'countryCode', \
'badPasswordTime', \
'lastLogoff', \
'lastLogon',\
'primaryGroupID', \
'accountExpires', \
'logonCount', \
'sAMAccountName', \
'sAMAccountType', \
'objectCategory', \
'pwdLastSet', \
'userAccountControl', \
'lastLogonTimestamp', \
'whenChanged', \
'uSNChanged', \
'dNSHostName', \
'isCriticalSystemObject', \
'msDS-SupportedEncryptionTypes', \
'operatingSystem', \
'operatingSystemVersion', \
'servicePrincipalName', \
'distinguishedName' ]
conn = ldap_connection()
conn.search(LDAP_BASE_DN, LDAP_OBJECT_FILTER, attributes=cmptr_attr_list)
# output to json
json_cmptrs_data = main_path + data_path + json_cmptrs_file
data = json.loads(conn.response_to_json())
with open(json_cmptrs_data, 'w') as jsonfile:
json.dump(data, jsonfile)
# copy data
json_cmptrs_arch = main_path + arch_patch + current_datetime + "_" + json_cmptrs_file
shutil.copy2(json_cmptrs_data, json_cmptrs_arch)
print("USERS:")
print("Data file created at: " + json_users_data)
print("Archive file created at: " + json_users_arch)
print("------------------------------------------------------------------------------")
print("COMPUTERS")
print("Data file created at: " + json_cmptrs_data)
print("Archive file created at: " + json_cmptrs_arch)
sys.exit(0)
# exit(0) -> OK
# exit(1) -> FAULT
my jsons output looks:
{"entries": [
{"attributes":
{
"accountExpires": ["9223372036854775807"],
"badPasswordTime": [],
"badPwdCount": [],
"cn": ["Bo\u017Cena \u017Ar\u00F3dlana"],
"codePage": ["0"],
"countryCode": ["0"],
"displayName": ["Bo\u017Cena \u017Ar\u00F3dlana"],
"distinguishedName": ["CN=Bo\u017Cena \u017Ar\u00F3dlana,OU=FE,OU=Users,OU=UNIVERSUM,DC=universum,DC=local"],
"givenName": ["Bo\u017Cena"],
"instanceType": ["4"],
"lastLogoff": [],
"lastLogon": [],
"lastLogonTimestamp": ["132978476924537530"],
"logonCount": [],
"memberOf": [],
"name": ["Bo\u017Cena \u017Ar\u00F3dlana"],
"objectCategory": ["CN=Person,CN=Schema,CN=Configuration,DC=universum,DC=local"],
"objectGUID": [
{
"encoded": "AFvzBO0T+Ey9TL3RHGtghQ==",
"encoding": "base64"
}
],
"objectSid": [
{
"encoded": "AQUAAAAAAAUVAAAA6TO9FZD9W8QoWlFDIE8AAA==",
"encoding": "base64"
}
],
"primaryGroupID": ["513"],
"pwdLastSet": ["132979783101549910"],
"sAMAccountName": ["pjarmolowicz"],
"sAMAccountType": ["805306368"],
"sn": ["\u017Ar\u00F3dlana"],
"uSNChanged": ["4986"],
"uSNCreated": ["4986"],
"userAccountControl": ["512"],
"userPrincipalName": ["bzrodlana#universum.local"],
"whenChanged": ["20220525185150.0Z"],
"whenCreated": ["20211125124337.0Z"]},
"dn": "CN=Bo\u017Cena \u017Ar\u00F3dlana,OU=FE,OU=Users,OU=UNIVERSUM,DC=universum,DC=local"
},
{"attributes": {
"accountExpires": ["9223372036854775807"],
"badPasswordTime": ["133128872888506790"],
"badPwdCount": ["0"],
"cn": ["Jan Kowalski"],
"codePage": ["0"],
"countryCode": ["0"],
"displayName": ["Jan Kowalski"],
"distinguishedName": ["CN=Jan Kowalski,OU=RR-32,OU=RR,OU=Users,OU=UNIVERSUM,DC=universum,DC=local"],
"givenName": ["Jan"],
"instanceType": ["4"],
"lastLogoff": [],
"lastLogon": ["133129921828641420"],
"lastLogonTimestamp": ["133125345565644950"],
"logonCount": ["55"],
"memberOf": [],
"name": ["Jan Kowalski"],
"objectCategory": ["CN=Person,CN=Schema,CN=Configuration,DC=universum,DC=local"],
"objectGUID": [
{
"encoded": "AScnTASpKUun4oadMC5Qxg==",
"encoding": "base64"
}
],
"objectSid": [
{
"encoded": "AQUAAAAAAAUVAAAA6TO9FZD9W8QoWlFDngQAAA==",
"encoding": "base64"
}
],
"primaryGroupID": ["513"],
"pwdLastSet": ["131577266641617910"],
"sAMAccountName": ["jkowalski"],
"sAMAccountType": ["805306368"],
"sn": ["Kowalski"],
"uSNChanged": ["149609"],
"uSNCreated": ["5397"],
"userAccountControl": ["512"],
"userPrincipalName": ["jkowalski#universum.local"],
"whenChanged": ["20221110061556.0Z"],
"whenCreated": ["20130610115016.0Z"],
"dn": "CN=Jan Kowalski,OU=RR-32,OU=RR,OU=Users,OU=UNIVERSUM,DC=universum,DC=local"
}
]
}
Use the following to suppress Unicode escape codes and write the data UTF-8-encoded to support non-ASCII characters.
with open(json_cmptrs_data, 'w', encoding='utf8') as jsonfile:
json.dump(data, jsonfile, ensure_ascii=False)
Working example:
import json
data = {"cn": ["Bo\u017Cena \u017Ar\u00F3dlana"]}
with open('output.json', 'w', encoding='utf8') as file:
json.dump(data, file, ensure_ascii=False)
output.csv (UTF-8-encoded):
{"cn": ["Bożena źródlana"]}

botocore.exceptions.ClientError: An error occurred (InvalidInstanceID.Malformed)

Any suggestion pls, Here is the code, works fine if i call function as get_instance_name ('i-0368cdfdded') and error i get is
Tried ids.txt as both 'i-xxxx' or i-xxx
botocore.exceptions.ClientError: An error occurred (InvalidInstanceID.Malformed) when calling the DescribeInstances operation: Invalid id: "i-xxxxxx"
import boto3
AWS_REGION = "us-west-2"
AWS_PROFILE = "profilex"
session=boto3.session.Session(profile_name=AWS_PROFILE)
ec2 = session.resource('ec2', region_name=AWS_REGION)
def get_instance_name(fid):
i = ec2.Instance(fid)
instancename = ''
for tags in i.tags:
if tags["Key"] == 'Name':
instancename = tags["Value"]
return instancename
with open('ids.txt') as f:
for line in f:
get_instance_name ('line')
so what i found is i get expected output when i run the program in interactive python terminal but not run as program. I am not able to figure that out why, but the program itself works on console. Here is what i ran last which worked. ( I was doing many trial & errors )
import boto3
import sys
import os
import json
AWS_REGION = "us-west-2"
AWS_PROFILE = "xxxx"
session=boto3.session.Session(profile_name=AWS_PROFILE)
ec2 = session.resource('ec2', region_name=AWS_REGION)
def get_instance_name(fid):
i = ec2.Instance(fid)
instancename = ''
for tags in i.tags:
if tags["Key"] == 'Name':
instancename = tags["Value"]
return instancename
filename="xxx.txt"
with open(filename) as file:
while (line := file.readline().rstrip()):
#print(line)
get_instance_name(line)

FastAPI Query with dataclass not working with alias

the following FastAPI code is producing unexpected behaviour to me:
import uvicorn
from fastapi import FastAPI, Depends, Query
from typing import Optional
from pydantic.dataclasses import dataclass
app = FastAPI()
#dataclass
class Catz:
qqq: Optional[str] = Query(None, alias="q")
#app.get("/productz/")
def search_products(query: Catz = Depends(Catz) ):
products = [{"name": "Computer"}, {"name": "HDD"}]
if not query.qqq:
query.qqq = ""
return {"query": query, "results": [product for product in products if query.qqq in product["name"]]}
#dataclass
class Cats:
qqq: Optional[str] = Query(None )
#app.get("/products/")
def search_products(query: Cats = Depends(Cats) ):
products = [{"name": "Computer"}, {"name": "HDD"}]
if not query.qqq:
query.qqq = ""
return {"query": query, "results": [product for product in products if query.qqq in product["name"]]}
if __name__ == "__main__":
uvicorn.run("main:app", port=11978, log_level="info", reload=True)
when I use the service via curl, I get the following outputs:
the expected behaviour with the endpoint /products/ that has no aliases
>> curl -X 'GET' 'http://localhost:11978/products/?qqq=H' -H 'accept: application/json' -H 'api-version: 1.0' ; echo
{"query":{"qqq":"H"},"results":[{"name":"HDD"}]}
not the expected behaviour with the endpoint /productz/ that has no aliases (regardless of me using a query parameter with its own name or with the alias I have in the code)
>> curl -X 'GET' 'http://localhost:11978/productz/?qqq=H' -H 'accept: application/json' -H 'api-version: 1.0' ; echo
{"query":{"qqq":""},"results":[{"name":"Computer"},{"name":"HDD"}]}
>> curl -X 'GET' 'http://localhost:11978/productz/?q=H' -H 'accept: application/json' -H 'api-version: 1.0' ; echo
{"query":{"qqq":""},"results":[{"name":"Computer"},{"name":"HDD"}]}
any idea why that would be?
Do not import dataclass from pydantic.dataclasses - it should be imported from Python's own built-in dataclasses module:
from fastapi import FastAPI, Depends, Query
from fastapi.exceptions import RequestValidationError
from dataclasses import dataclass
from typing import Optional
app = FastAPI()
#dataclass
class Catz:
qqq: Optional[str] = Query(None, alias="q")
#app.get("/productz/")
def search_products(query: Catz = Depends()):
products = [{"name": "Computer"}, {"name": "HDD"}]
if not query.qqq:
query.qqq = ""
return {"query": query, "results": [product for product in products if query]}
Outputs for /productz?q=123:
{"query":{"qqq":"123"},"results":[{"name":"Computer"},{"name":"HDD"}]}

How to get a list of all forks of a GitHub repo on Linux?

I would like to have a simple, non-interactive way to get a list of forks of a GitHub repo.
For me personally, it has to run on at least Linux.
Using GraphQL (GiHub API v4) from a bash script, using cURL:
#!/bin/bash
# Returns a list of all forks of a github repo.
# See the output of "$0 -h" for more details.
set -e
# initial default values
access_token=""
repo_owner=$USER
repo_name=$(basename $(pwd))
res_file=res.json
function print_help() {
echo "Returns a list of all forks of a github repo."
echo
echo "Usage:"
echo " `basename $0` [OPTIONS]"
echo "Options:"
echo " -h, --help Show this help message"
echo " -o, --owner <string> Name of the GitHub user or organization of the original repo"
echo " -r, --repo <string> Name of the GitHub original repo"
echo " -t, --token <string> GitHub personal access token, required for authentication"
echo " To get one, see: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line"
}
# read command-line args
POSITIONAL=()
while [[ $# -gt 0 ]]
do
arg="$1"
shift
case "${arg}" in
-h|--help)
shift # past argument
print_help
exit 0
;;
-o|--owner)
repo_owner="$1"
shift # past argument
;;
-r|--repo)
repo_name="$1"
shift # past argument
;;
-t|--token)
access_token="$1"
shift # past argument
;;
*) # non-/unknown option
POSITIONAL+=("${arg}") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[#]}" # restore positional parameters
if [ -z "$access_token" ]
then
>&2 echo "WARNING: Access token not specified, though it is required!"
print_help
exit 1
fi
curl \
'https://api.github.com/graphql' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Connection: keep-alive' \
-H 'Origin: altair://-' \
-H "Authorization: Bearer $access_token" \
--data-binary '{"query":"query { repository(owner: \"'$repo_owner'\", name: \"'$repo_name'\") { forks(first:100) { edges { node { nameWithOwner } } } } }","variables":{}}' \
--compressed \
> "$res_file"
cat "$res_file" \
| sed -e 's/nameWithOwner/\nXXX/g' \
| grep XXX \
| awk -e 'BEGIN { FS="\""; } { print $3; }'
You need to create an access token.
Sample invocation of the above script:
git-hub-list-forks -o hoijui -r JavaOSC -t 1234567890abcdef1234567890abcdef
NOTE: GitHub limits the maximum amount of forks to fetch to 100 at a time
if you are interested in a js based solution you try GitHub rest API:
/repos/{owner}/{repo}/forks
fetch("https://api.github.com/repos/ONLYOFFICE/CommunityServer/forks?sort=stargazers")
.then(response => response.json())
.then(res=> {
let result = res.map(e=> {
return {
url: e.html_url,
watchers: e.watchers,
starts: e.stargazers_count,
updated_at:e.updated_at
};
});
console.log(result);
// or console.table(result);
});

Unificationengine not working with instagram

When I am sharing a message on instagram by UnificationEngine then I am getting this error:
Exception in UEUser.php line 74: The password you entered is incorrect. Please try again in UEUser.php line 74
at UEUser->add_connection('instagramBoard', 'instagram', '4544942713.7da612b.4de7a5a78fb0491dba2b27a60dc1749d') i
My Code is:
$app = new UEApp("APP_KEY","APP_SECRATE");
$user = new UEUser("USER_KEY", "USER_SECREATE");
$con = $access_token ."#instagram.com/?username=rajneesh8239&password=testing1";
$connection = $user->add_connection("instagramBoard", "instagram", $con);
$options = array(
"receivers" => array(
array(
"name"=> "Me"
)
),
"message"=>array(
"subject"=>"Transparentcom testing fine",
"body"=> "",
"image"=> '',
"link"=>array(
"uri"=> '',
"description"=> "",
"title"=>"Click here for view"
)
)
);
//Send the message and get their uris
$uris = $connection->send_message($options);
CURL error:
vagrant#homestead:~/Code/laravel$ curl -XPOST https://apiv2.unificationengine.c
om/v2/user/create -u 590f402bd2a043f98823eb1940b2ab:a62c855ae17b5cacb355abfbcc3a93 --data '{}'
{"status":200,"info":"200 OK","uri":"user://0e4946b0-9e60-4e0f-b54-f4e39ab5b0b:0490d37c-e284-422e-b8de-00b5f81ff81#"}
vagrant#homestead:~/Code/laravel$ curl -XPOST https://apiv2.unificationengine.c
om/v2/connection/add -u 0e494b0-9e-4e0f-ab54-f4eab53b0b:04937c-e284-422e-b8de-003b5f81ff81 --data '{"uri":"instagram://4544942713.7da612b.4de7a5a78fb0491dba2b327a60dc1749d#instagram.com", "name":"instagram"}'
{"status":500,"info":"incorrect Password"}
Please use this code like this way, You need to just change this line like this way.
$con = $access_token."#instagram.com/?username=rajneesh8239&password=testing1";
$connection = $user->add_connection("instagramBoard", "instagram", $con);
Please check with code

Resources