Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Consider the variable 'logdata' which is a string containing a standard web log. This variable records the access a user makes when visiting a

Question:

Consider the variable 'logdata' which is a string containing a standard web log. This variable records the access a user makes when visiting a web page (like this one!). Each line of the log has the following items:

  • a host (e.g., 146.204.224.152)
  • a username (e.g., feest6811 or sometime '-' since it is missing)
  • the time a request was made (e.g., 21/Jun/2019:15:45:24 -0700)
  • the post request type (e.g., POST /incentivize HTTP/1.1)

Your task is to fix the incorrect regex between ### BEGIN CODE and ### END CODE to convert the given data into a list of dictionaries, where each dictionary looks like the following:

example_dict = {"host":"146.204.224.152", "user_name":"feest6811", "time":"21/Jun/2019:15:45:24 -0700", "request":"POST /incentivize HTTP/1.1"}

Failed info (need detailed explain, thank you!)

The following cell failed:

1 assert len(logs()) == 979 * HIDDEN TESTS The error was:

---------------------------------------------------------------------------

AssertionError Traceback (most recent call last)

in

* HIDDEN TESTS

8

* HIDDEN TESTS

AssertionError: Sorry, this item should be in the log results, check your formating

My answer

import re def logs(): with open("assets/logdata.txt", "r") as file: logdata = file.read() ### BEGIN CODE #pattern = """ #([.]+) # host %h #\s\-\s(.+)\s # user %u #\[(.+)\] # time %t #\s\"(\w\.+)\" # request %r #""" #result = [item.groupdict() for item in re.findall(pattern,logdata,re.VERBOSE)]

### END CODE

# YOUR CODE HERE pattern = """ (?P[\d]*.[\d]*.[\d]*.[\d]*) (\ -\ ) (?P[\w-]*) (\ \[) (?P

assert len(logs()) == 979

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

describe the services that an outplacement consultancy may provide.

Answered: 1 week ago