if(re.search("USN:.*MediaRenderer", datagram, flags=re.IGNORECASE)):
deviceXML = re.search("LOCATION:(.*.xml)", datagram, flags=re.IGNORECASE).group(1)
I am getting pytlint error "line too long" for 2nd line
How to correct this ?
Cut your line to meet the length (80 chars usually):
if(re.search("USN:.*MediaRenderer", datagram, flags=re.IGNORECASE)):
deviceXML = re.search("LOCATION:(.*.xml)",
datagram,
flags=re.IGNORECASE).group(1)
Or use your own customization of pylint.
Related
I am trying to send a large chunk emails and got error with message "Domain contains dot-dot".
Does anyone know why I am getting this error?
#0 /var/www/vhosts/domainame.com/vendor/aws/aws-sdk- php/src/Aws/Common/Exception/NamespaceExceptionFactory.php(76): Aws\Common\Exception\NamespaceExceptionFactory->createException('Aws\\Ses\\Excepti...', Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response), Array)
#1 /var/www/vhosts/domain.com/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/ExceptionListener.php(55): Aws\Common\Exception\NamespaceExceptionFactory->fromResponse(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response))
#2 [internal function]: Aws\Common\Exception\ExceptionListener->onRequestError(Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Compone in /var/www/vhosts/domainname.com/vendor/guzzle/guzzle/src/Guzzle/Service/Exception/CommandTransferException.php on line 25
PHP Fatal error: Uncaught exception 'Guzzle\Service\Exception\CommandTransferException' with message 'Errors during multi transfer
(Aws\Ses\Exception\SesException) /var/www/vhosts/domainname.com/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php line 91
Domain contains dot-dot
Domain name of some mail address contains more then one dot sign (.) literally.
eg. Alan#stackoverflow..com
Reference:
1.
https://java.net/projects/javamail/sources/mercurial/diff/mail/src/oldtest/java/javax/mail/internet/addrlist?rev1=61&rev2=62
https://java.net/projects/javamail/sources/mercurial/content/mail/src/main/java/javax/mail/internet/InternetAddress.java?rev=557
I want to print lines before my /ERROR/ match. The lines to be printed should be all containing INFO untill the previous ERROR is found.
So If I had a file
ERROR this is an error
INFO error found on line 2
INFO error is due to something
ERROR this is another error
I want the /ERROR/ from ERROR this is another error to print
INFO error found on line 2
INFO error is due to something
ERROR this is another error
Anyone know?
Part of my current script:
/CRITICAL/ {
print "\x1b[93;1m"
}
/ERROR/ {
print "\x1b[37m"
}
/ERROR|EMERGENCY|CRITICAL/ {
if (NR == n+1) print "";
n = NR;
print x;print
print "\x1b[0m"
};{x=$0}'
Try this one liner:
awk 'x;/ERROR/{x=1}' file
Out:
INFO error found on line 2
INFO error is due to something
ERROR this is another error
Long version:
x;/ERROR/{
x1=1;
print
}
If "ERROR" is found x=1, if x is true we've already gone through that line, then we print until we pass that line again.
Or maybe this, I don't have very clear what output you need.
awk '/ERROR/{x=1;next}/ERROR/{x=1}x'
Out
INFO error found on line 2
INFO error is due to something
I have implemented a script to parse ERF file to get the DNS records from the packets. The script works under Linux but DOES NOT work under Windows.
I have tried to simplify it and read only two packets from the file and the result was totally wrong.
Here is the output for the first two packets:
rlen 1232
wlen 1213
ts: (5822080496043415499L,)
rec len: 1232
protocol: 6 rem 1180
tcp
src port: 59626
remaining length based on the erf header 1160 remaining length based in IP total length 1155
----------------------
rlen 44076
wlen 13638
ts: (246640611164160L,)
rec len: 44076
protocol: 9 rem 44024
----------------------
for the first packet the output is correct, but for the second one everything is wrong. What I did was reading the record length from the ERF header to keep track of the packet boundaries. When I printed the payload of the tcp I found that the erf header of the next packet was in the payload of tcp. This problem didn't occur when I ran the code under linux.
Can anyone tell me what I'm doing wrong?
Here is my code:
if __name__ == '__main__':
argv= sys.argv
outputFile=''
inputFile=''
dnsPacketCounter=0
ethH = {}
ipHeader = {}
ipH = {}
totalPackets=0
if len(argv) ==1:
print 'erfParser.py -i <inputfile> -o <outputfile>'
sys.exit(0)
elif len(argv) == 2:
if argv[1] == '-h':
print 'erfParser.py -i <inputfile> -o <outputfile>'
sys.exit(0)
elif len(argv) == 5:
if argv[1] == '-i':
inputFile = argv[2].strip()
elif argv[3] == '-i':
inputFile = argv[4].strip()
if argv[1] == '-o':
outputFile = argv[2].strip()
elif argv[3] == '-o':
outputFile= argv[4].strip()
else:
# Open the trace file
print 'erfParser.py -i <inputfile> -o <outputfile>'
sys.exit(0)
try:
packets = open(inputFile , 'r+')
except IOError:
print 'The file: ',inputFile,' not found.'
sys.exit(0)
try:
outFile=open(outputFile+'.txt', 'w+')
except IOError:
print 'The file: ',outputFile,' can not be opened.'
sys.exit(0)
ts=packets.read(8)
i=0
while ts:
erf={}
hdr = packets.read(8)
#print ts.encode('hex')
totalPackets=totalPackets+1
erf= getERFHeader(ts,hdr)
print 'rlen',erf['rlen']
print 'wlen',erf['wlen']
print 'ts: ',erf['ts']
remainingLength=erf['rlen']- 16
print 'rec len: ',erf['rlen']
if erf['type'] == 0x07:
ext=packets.read(8)
remainingLength=remainingLength- 8
pad=packets.read(2) # pad
remainingLength=remainingLength- 2
ethH= packets.read(14) # ethernet header `16 bytes
remainingLength=remainingLength- 14
ipHeader= packets.read(20) #ip header length is 20 bytes
remainingLength=remainingLength- 20
ipH= getIPHeader(ipHeader)
print 'protocol: ',ipH['protocol'],' rem ',remainingLength
if ipH['protocol'] ==TCP:
print 'tcp'
hdr = packets.read(20)
remainingLength=remainingLength- 20
tcpHeader=getTCPHeader(hdr)
tcpPayload= packets.read(remainingLength)
print 'src port: ',tcpHeader['srcPort']
# print 'tcp payload in hex: ',tcpPayload.encode('hex')
print 'remaining length based on the erf header',remainingLength,'remaining length based in IP total length' ,ipH['totalL']-40
print '----------------------'
ts=packets.read(8)
i=i+1
if i==2:
break;
pass
Can anyone tell me what I'm doing wrong?
Yes, I can tell you that you're opening the file in text mode rather than binary mode:
packets = open(inputFile , 'r+')
To quote the Python documentation for open():
Modes 'r+', 'w+' and 'a+' open the file for updating (reading and writing); note that 'w+' truncates the file. Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files; on systems that don’t have this distinction, adding the 'b' has no effect.
UN*Xes such as Linux are "systems that don't have this distinction", because the Python open() is modeled after the UN*X version of the "standard I/O library", in which lines end with a \n. On Windows, lines end with \r\n, and opens in the "standard I/O library" can either:
open in text mode, in which the \r\n at the ends of lines, when read, are shown to the program as a \n, and a \n, when written to a line, is written as \r\n, so that programs written for UN*X can work on Windows without having to worry about the end-of-line sequence;
open in binary mode, in which case a read gives you exactly the bytes that are in the file, and a write puts the bytes given to it into the file;
so it's a system that "[differentiates] between binary and text files", at least in some of the I/O libraries. (At the lowest level of I/O, namely the CreateFile(), ReadFile(), and WriteFile() calls, Windows makes no such distinction - it treats files as sequences of raw bytes, with no "open as text" option, just as UN*X systems do with open(), read(), and write() - but at all levels of I/O intended to be somewhat UN*X-compatible, they provide a text vs. binary option.)
ERF files are binary files, so you need to open with 'rb+' or 'r+b', not 'r+'. That will make no difference on UN*Xes such as Linux, but will give you raw binary data on Windows.
(Actually, just 'rb' will suffice - if you don't plan to write to the file you're reading, the + isn't necessary, and creates the risk of accidentally overwriting the file.)
The following
let new_socket () = Lwt_unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
let socket_address = Network.make_address "127.0.0.1" 7777 in
let listening_socket = new_socket () in
Lwt_unix.setsockopt listening_socket Unix.SO_REUSEADDR true;
Lwt_unix.bind listening_socket socket_address;
results into this error:
Error: correctness:2:remote_client:0:set
Unix.Unix_error(Unix.EADDRINUSE, "bind", "")
Raised at file "src/core/lwt.ml", line 782, characters 22-23
Called from file "src/unix/lwt_main.ml", line 34, characters 8-18
Called from file "src/oUnit.ml", line 597, characters 6-10`
Last line fails to grant the bind, ideas why, how to pass this?
The error is clearly stated: the address you are trying to bind to is already in use, a socket is is already bound on port 7777.
To understand the codes of the Unix_error raised by a function look in the manual of the corresponding C unix function, in that case bind(2).
I'm just writing a little client side HTTP application. It just sends a GET Request to an IP Camera and then receives a Screenshot in jpeg format.
Now for the implementation of HTTP I am using Boost Asio. So for the first try I oriented pretty much at the sync_client example Boost Asio Sync HTTP Client Example.
Now mainly I'm a bit worried by the separation of Headers and Data.
First I get the first line of the response:
boost::asio::streambuf response;
boost::asio::read_until(*m_Socket, response, "\r\n");
std::istream response_stream(&response);
std::string http_version;
response_stream >> http_version;
if (!response_stream || http_version.substr(0, 5) != "HTTP/")
{
std::cout << "Invalid response\n";
return;
}
uint32_t status_code;
response_stream >> status_code;
std::string status_message;
std::getline(response_stream, status_message);
if (status_code != 200) // 200 = status code OK
{
std::cout << "Response returned with status code " << status_code << "\n";
return;
}
Now until here everything is clear to me.I'm reading until first new line and then check the stuff in my buffer.
Now I'm trying to read the second part of the header:
boost::asio::read_until(*m_Socket, response, "\r\n\r\n");
std::string header;
while (std::getline(response_stream, header) && (header != "\r"))
{
std::cout << header << "\n";
}
std::cout << "\n";
Now to this I have some questions:
The while loop is searching until there is a blank line ( the only line where a \r stands all by itself ). Now if I assume that a new line is defined by \r , why do I use \r\n\r\n at boost::asio::read_until ? I mean I would expect wether the one or the other, but both?
If I call the boost::asio::read_until method with \r\r as delimiter it throws an End of File exception. This stands in contrary to what my while loop is searching since this is looking for a \r\r ( since it looks line after line, and every line closes with a \r )
So as you can see Im quite worried how to divide stuff inside my header. It's getting even worser because the boost::asio::read_until call does always read further than the delmiter ( this is actually OK, since it's mentioned in the documentation ), but still it kinda always has the same trail of data ( from the actualy jpeg ), with the same length following.
Maybe someone could enlighten me?
'\r' is the carriage return (CR) character and '\n' is the line-feed (LF) character. HTTP message lines are terminated by "\r\n" (CRLF).
From "HTTP The Definitive Guide":
It is worth pointing out that while the HTTP specification for
terminating lines is CRLF, robust application also should accept just
a line-feed character. Some older or broken HTTP applications do not
always send both the carriage return and line feed.
What seems to be throwing you off is that some line I/O functions (in this case std::getline()) automatically strip the trailing '\n' so you are only seeing the preceding '\r'. I think what you should be doing, is looking for a blank line (rather than a line with only '\r'). And a line that is only '\r' should be considered a blank line.
The "\r\n\r\n" delimiter is used to separate the headers from the actual server's response(which is the JPEG image you are fetching). That's why you're using it; headers are separated by "\r\n".
You should read until "\r\n\r\n". Everything that comes afterwards is the JPEG image. Note that you can guess the length of the file by checking the Content-Length header, or just read until the server closes the socket.