Testing Django API on a VPS with curl - django

I'm trying to access on my Django API using curl from my local terminal to a VSP
curl -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/
So, I tried many things like,
replace admin:password to my actual vps root#password
replace admin:password to my actual database admin#password
replace http://127.0.0.1:8000 to my vps url
replace the port 8000 by 22, or 80, 8080
And by the way, I don't know is I have to change /users/ by /root/ or anything else.
I have tried many mix and nothing works.
Here what I'm testing : http://www.django-rest-framework.org/tutorial/quickstart/#testing-our-api
If important, my vps machine is Debian 9 (Stretch)
Think you for your help

This worked for me:
curl -H 'Accept: applicatin/json; indent=4' -u [superuser username]:[superuser password] http://YOURVPSIPADDRESS/users/
The admin:password should be the superuser username and password on your Django site not the username or password for your database or VPS. Ensure a superuser has been created for your Django site on your VPS.

Related

Solr 9 UI not loading but working with CLI

Recently updated the solr version from 8.4.1 to 9.0.0 on EC2 Linux AMI 2.
I'm getting the result when i'm using the cli using the localhost domain-> curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET "http://localhost:8983/solr/core_name/select?q=(fieldname%3A\fieldvalue%20)&start=0".
But when I try to use the EC2's elastic IP it says the connection refused. It was working well with the previous version. I configured it locally before trying in EC2, it worked fine in local but not on EC2.Not sure what's missing.
Scrrenshot of browser response
Solr Status
Solr status screenshot
Uncommented and changed the SOLR_JETTY_HOST from 127.0.0.1 to 0.0.0.0 in solr.in.sh file. Deleted everything and reindexed the core after updating the jetty host.

```curl: (52) Empty reply from server``` ERROR response from aws ECR

I am trying to make a curl request to get ECR Authorization token instead of using aws cli.
I referred https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_GetAuthorizationToken.html
And to generate signature, I referred this : https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
curl -v --location --request POST 'https://ecr.us-east-1.amazonaws.com:443' -H 'Accept-Encoding: identity' -H 'Content-Length: 1590' -H 'X-Amz-Target: AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken' -H 'X-Amz-Date: 20151129T221940Z' -H 'User-Agent: aws-cli/1.17.14 Python/2.7.5 Linux/3.10.0-957.1.3.el7.x86_64 botocore/1.14.14' -H 'Content-Type: application/x-amz-json-1.1' -H 'Authorization: AUTHPARAMS {AWS4-HMAC-SHA256 Credential=AKIA*******/20200514/ap-south-1/ecr/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=ffe96d25bba760d7502993a1dbf0*********************}'
Response returned after few minutes is :
* Empty reply from server
* Connection #0 to host ecr.ap-south-1.amazonaws.com left intact
curl: (52) Empty reply from server
I basically want to use this token in making a curl request to return ECR image tags:
curl -i -s -H "Authorization: Basic TOKEN" https://90********.dkr.ecr.ap-south-1.amazonaws.com/v2/image-name/tags/list
If i can request the image tags using above command without Token generation....please provide the answer.
this error means that you are receiving a 502 response error, bad gateway. I had a similar when tried to run a curl command via ssh inside an instance hosted on EC2, so I figured out that I had deployed my image with the port mappings incorrectly. I would recommend you to check the following:
Check if your security group allows traffic on port 433
Check if you have deployed your container with the port mappings correctly to ECR, like this:
suppose you have an image called list
To run in your local machine you should execute the following command
docker run -d -p 80:433 list
make sure you have mapped these ports correctly on your Dockerfile, then tag your image
docker tag list 90********.dkr.ecr.ap-south-1.amazonaws.com/v2/image-name/tags/list
and push to ECR
docker push 90********.dkr.ecr.ap-south-1.amazonaws.com/v2/image-name/tags/list
once you have your image pushed to ECR you can run it
docker run -d -p 80:433 90********.dkr.ecr.ap-south-1.amazonaws.com/v2/image-name/tags/list
and then you can curl your image
curl http://ecr-image/your/path

Calling Webservice from NIFI with proxy

I need to configure a NIFI flow that invokes a webservice. The curl command works fine from the cmd line of my nifi host
curl -U <user>:<password> -x <ip>:8080 -H 'SOAPACTION:"http://method"'-X POST -H 'Content-type: text/xml' -d #req.xml https://url -o result2.xml
Im trying to configure NIFI InvokeHTTP processor to make the call from within a nifi flow with following settings.
HTTP Method:POST
Remote URL: https://url
Proxy Host: <ip>
Proxy Port: 8080
Proxy Username: <user>
Proxy Password: <password>
SOAPAction: method (Dynamic Properties)
But it keeps running in the Failure queue.
how do i configure my InvokeHTTP according to the curl command which works ok?
We updated the version of the InvokeHTTP component from 1.3.0 to the newest

able to run rails server from production server directly but not pulling website from domain name

able to run rails server from production server directly but not pulling website from domain name,
I have an rails app which is deployed on EC2 instance with unicorn+nginx, both the things are running.
If I run rails s RAILS_ENV=production, it runs properly on ip address:3000, but when I enter hostname www.example.com, it shows error 522 connection timeout
Any help on this, I tried googling but nothing helped.
This may work
rails s -e production -b your_host_ip -p 80
OR
rails s -e production -b 0.0.0.0 -p 80
OR
rails s -e production -b domain -p 80

How to view the webpage in Django tutorial on Linode server

I know I have similar question with this post: Django tutorial on remote server: how to view in my browser? But I just can't solve it with the answer it has.
I am playing with Django framework now. I am trying to do the Django tutorial on my Linode server. Everything works fine, but when we have to examine the webpage we have, the tutorial says that we have to check http://127.0.0.1:8000/ on the server. I only have command line access on the Linode server, so I don't know how to see that webpage on the linode from my desktop. I tried to use the command like python manage.py runserver 123.123.123.123:8000 and set the ip to my Linode server, but I still can't access that webpage from my desktop (I do remove the firewall for 8000 port). Does anyone know how can I check the change for the remote webpage I created within Django framework on the Linode server? Thanks.
Just to make sure, are you trying to access the following URL in your browser (where the server ip address is 123.123.123.123)?
http://123.123.123.123:8000
Secondly, are you able to telnet to port 8000, to make sure you have correctly opened the port on the firewall.
I had this problem too and I wanted to clarify what I did for others who might get stuck:
First, remove the firewall for port 8000
sudo nano /etc/iptables.firewall.rules
-A INPUT -p tcp --dport 8000 -j ACCEPT
Second, reboot the linode
Third, restart the development server
cd /home/mycode/mysite
python manage.py runserver 123.123.123.123:8000
(where you use your ip)