API doesn't work. (IP-API) - api

I wanted the IP-API resolve the IP that I got in the first link, but it does not work.
#!/usr/bin/python
import sys
import requests
print "Conectando com %s" % sys.argv[1]
Get_Skype = requests.get("http://api.predator.wtf/resolver/?arguments=%s" % sys.argv[1]).text
print "Entrando em %s" % Get_Skype
My_API = requests.get("http://ip-api.com/json/%s" % Get_Skype).text
print My_API
Command Line:
$ python script.py user_skype
The api returns:
{"message":"invalid query","query":"<ip>","status":"fail"}

The result of the request "http://api.predator.wtf/resolver/?arguments=user_skype" which is stored in Get_Skype is
Crap, No IP Was Found!
and not a valid IP which causes your api consider it a bad query (which it actually is). So you probably should first check this result being a valid IP address, before passing it to API.
If a valid username is entered, the result of the predator query has a trailing \ufeff character, which is BOM. See here how to deal with it.

Related

What am I doing wrong with my CGI Script? [duplicate]

This question already has answers here:
How can I troubleshoot my Perl CGI script?
(8 answers)
Closed 3 months ago.
I am still fairly new to this and I am trying to run this CGI Script on my apache server. When I go to the webpage all I get is a blank page. What am I doing wrong?
#!/usr/bin/perl
use CGI qw(:standard);
print"Content-type: text/html \n\n";
$cost=param('cost');
$num=param('number');
$rev=param('revenue');
$avg = $cost/$num;
$avg=sprintf("%.2f",$avg);
$gp = $rev - $cost;
print "Project Cost Last Year was \$ $cost .<p>";
print "We completed $num projects during the year.";
print " That works out to an average of \$ $avg cost per project.";
print "<p>Our annual project revenue was \$ $rev <br>";
print "We made a gross profit of \$ $gp \n";
That is my current code for the script. I have made sure that my the file is executable as well.
the url i used was 192.168.1.49/cgi-bin/cgi.cgi
I believe you mean http://192.168.1.49/cgi-bin/cgi.cgi.
Given that request URL, what exactly do you expect to happen for the following?
$cost=param('cost');
$num=param('number');
$rev=param('revenue');
$avg = $cost/$num;
Since you didn't provide a value for the number parameter, $num is undef and treated as zero in $avg = $cost/$num;.
Division by zero makes the CPU sad.
You should have figured this out yourself.
An exception like this would have caused the server to return an HTTP status of 500. This indicates you should read your error logs, where you would have found the following message:
Illegal division by zero at [filename] line 7.
If you had used use warnings; as normal, you would also have received these errors:
Use of uninitialized value $num in division (/) at [filename] line 7.
Use of uninitialized value $cost in division (/) at [filename] line 7.
Always use use strict; use warnings;.
Your code suffers from MAJOR security bugs.
Specifically, your code suffers from code injection bugs which can easily be exploited for cross-site scripting attacks and url redirection attacks.
Text included in HTML needs to be converted to HTML.

Argparser interactive

My question is pretty straight,
Is argaparse has an option to prompt missed arguments just via input?
script.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('mode', metavar='', help='Set count of likes', default=49)
parser.add_argument('-n', '--number', metavar='', help='Set count of likes', default=49, required=True)
parser.add_argument('-f', '--frequency', metavar='', help='Set chance to like/dislike', default=70)
# Running it via bash:
$ python script.py
# argparse automaticaly checking that missed argument "--number" and asking it via input built-in
>>> (argparse) Missed required argument "number", please specify it now, number:

Universal Robot TCP/IP communication: cannot send crlf ("\r\n")

I'm trying to get our UR5e to talk to query another machine via TCP/IP.
This machine requires each received command to end with "\r\n" (I cannot change this).
This is the problem.
I cannot get the UR to append "\r\n" to the command because the backslashes are escaped automatically.
This is what I've tried so far:
socket_send_string("command\r\n") # results in "command\\r\\n"
socket_send_string("command")
socket_send_byte(13)
socket_send_byte(10) # results in "command\r"
socket_send_line("command") # results in "command\n"
Any help appreciated.

In Google collab I get IOPub data rate exceeded

IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
--NotebookApp.iopub_data_rate_limit.
Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)
An IOPub error usually occurs when you try to print a large amount of data to the console. Check your print statements - if you're trying to print a file that exceeds 10MB, its likely that this caused the error. Try to read smaller portions of the file/data.
I faced this issue while reading a file from Google Drive to Colab.
I used this link https://colab.research.google.com/notebook#fileId=/v2/external/notebooks/io.ipynb
and the problem was in this block of code
# Download the file we just uploaded.
#
# Replace the assignment below with your file ID
# to download a different file.
#
# A file ID looks like: 1uBtlaggVyWshwcyP6kEI-y_W3P8D26sz
file_id = 'target_file_id'
import io
from googleapiclient.http import MediaIoBaseDownload
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
# _ is a placeholder for a progress object that we ignore.
# (Our file is small, so we skip reporting progress.)
_, done = downloader.next_chunk()
downloaded.seek(0)
#Remove this print statement
#print('Downloaded file contents are: {}'.format(downloaded.read()))
I had to remove the last print statement since it exceeded the 10MB limit in the notebook - print('Downloaded file contents are: {}'.format(downloaded.read()))
Your file will still be downloaded and you can read it in smaller chunks or read a portion of the file.
The above answer is correct, I just commented the print statement and the error went away. just keeping it here so someone might find it useful. Suppose u are reading a csv file from google drive just import pandas and add pd.read_csv(downloaded) it will work just fine.
file_id = 'FILEID'
import io
from googleapiclient.http import MediaIoBaseDownload
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
# _ is a placeholder for a progress object that we ignore.
# (Our file is small, so we skip reporting progress.)
_, done = downloader.next_chunk()
downloaded.seek(0)
pd.read_csv(downloaded);
Maybe this will help..
from via sv1997
IOPub Error on Google Colaboratory in Jupyter Notebook
IoPub Error is occurring in Colab because you are trying to display the output on the console itself(Eg. print() statements) which is very large.
The IoPub Error maybe related in print function.
So delete or annotate the print function. It may resolve the error.
%cd darknet
!sed -i 's/OPENCV=0/OPENCV=1/' Makefile
!sed -i 's/GPU=0/GPU=1/' Makefile
!sed -i 's/CUDNN=0/CUDNN=1/' Makefile
!sed -i 's/CUDNN_HALF=0/CUDNN_HALF=1/' Makefile
!apt update
!apt-get install libopencv-dev
its important to update your make file. and also, keep your input file name correct

Is it possible to implement a break statement using a user input in python

time=0
stop=input()
while time<1000000000000000000000000000000000000000000000000000:
if stop==input("999"):
break
print (time)
time= time+1
print("time taken is",time)
This is a program for an average speed camera. I was wondering whether it is possible for the while loop to stop when the user inputs "999". The value at which the code is broken would then be the new content of the time variable.
It's a bit unclear of what you're trying to accomplish, but based on the code you provided and your question, it sounds like you want to measure how long it takes for someone to enter a specific value. You can modify: Python - Infinite while loop, break on user input:
#guess_999.py
import sys
import os
import fcntl
import time
fl = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL)
fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK)
time_started = time.time()
while True:
try:
stdin = sys.stdin.read()
if "999" in stdin:
print "It took %f seconds" % (time.time() - time_started)
break
except IOError:
pass
Then running it:
$ python guess_999.py
$ 6
$ 999
$ It took 2.765054 seconds
EDIT: PO wanted to do something completely different. I refer to Mark's answer.
You messed it up a little bit ;)
Do:
answer = input("type something")
if answer == "999":
break
Explanation:
- input() will return a string of what the user typed into the console. What you write into the brackets is what will be written on the line when you are asked to type something. This is usually a question like "what's your name?"
- if the answer is "999", the command break will be executed => loop stops