mercredi 27 octobre 2021

urllib sometimes doesn't open websites

I have a problem I can't really fathom... Sometimes I provide a Python app with a link to a txt web page and the app processes it as expected but sometimes I simply get errors, although the links seem basically identical (meaning they're both simple text-based web pages).

For example, I have a simple code like this:

import urllib.request, urllib.parse, urllib.error


link = input("Link: ")

fhand = urllib.request.urlopen(link)

for line in fhand:
    print(line.decode())

When I type http://data.pr4e.org/romeo-full.txt as a link, it works. But when I type https://www.py4e.com/code3/romeo.txt, it doesn't. How come?

The errors I get:

Traceback (most recent call last):

  File "C:\Users\lukas\AppData\Roaming\JetBrains\PyCharmCE2021.2\scratches\scratch_11.py", line 7, in <module>
    fhand = urllib.request.urlopen(link)
  File "C:\Users\lukas\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\lukas\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "C:\Users\lukas\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "C:\Users\lukas\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "C:\Users\lukas\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\lukas\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden



how to change div border-color by input value?

How to change div border-color by input value?

My Code

function myFunction() {
   var color = document.getElemntByID("inpx").value; document.getElementById("divx").style.borderColor = color;
  }
<!DOCTYPE html>
<html>
<head> </head>
<body> 
  <div id=divx"> </div>
  <button onClick=""> </button>

  <script>
  
  </script>
</body>
</html>



What are the best resources for learning web software architecture?

I have four years of experience in software engineering, and now I am close to finishing my degree in Computer Science.

My main passion is software architecture in web applications, and I will be glad to get guidance from top resources to learn web software architecture.

I prefer reading books or watching videos from my TV on reading on online web blogs or the internet.

I appreciate any help you can provide.




Is there a website builder component can I inject in my application

Is there a website builder component can I inject in my application instead of develop new website builder?




Warn web user if the back button was pressed using javascript

Hi I tried to use the following javascript to warn users.

 window.onbeforeunload = function() {
       return "Are you sure you wish to leave?";
    };

But I need to make sure that the back button is pressed it seems to call this when you change the url.

Thanks




Why is countryflags.io website and API down? Alternatives? [closed]

I am trying to access to https://www.countryflags.io website and use its API and I am getting an Error 522.

Does anyone has any information about it and/or knows any alternative to it?

Thanks in advance, Danny




I want different text in the same line positioned to the left and right inside a table cell

I am making a school timetable mock in HTML and CSS and I am having troubles with one specific thing and that is having 2 different pieces of text in the same line one positioned to the top left and the other to the top right. I have tried using float but that makes the text move down to text that is under it.

Here is the code used: https://jsfiddle.net/zhu2a1y4/

Here is the HTML code:

    <table class="separated">
        <tr>
            <td>
                <div class='cell_header'>
                    <p class="group">s1</p>
                    <p class="classroom">N228</p>
                <div>
                <h3>S: ICT</h3>
                <p>KOH</p>
            </td>
        </tr>
        <tr>
            <td>
                <p>s1 N228</p>
                <h3>L: ICT</h3>
                <p>KOH</p>
            </td>
        </tr>
    </table>

And here is the CSS:

*{
padding: 0px;
}
table, td {
    border: solid black 1px;
    border-collapse: collapse;
    text-align: center;
    column-width: 200px;
    height: 100%;
}
.separated td, .separated{
    border: 0px;
    border-bottom: 1px solid black;
    height: 100%;
}
.cell_header p {
    display: inline;
    position: relative;
    overflow: auto;
    margin-top: 0;
}
.classroom{
    text-align: right;
    float: right;
}
.group{
    text-align: left;
    float: left;}

As you can see in the example the text "s1" and "N228" are Next to "S:ICT" and my objective is to have both of the pieces of text higher up in the corners.

Any help would be much appreciated.

Thank you in advance and best regards

Davza