I have a PyScript running on the home.html page of a website, and within the script I'd like to read some information from a file stored in same directory as the home.html page but I always get error "Host is unreachable".
I expect to be able to read information from a file stored in same directory as my home.html page containing the script.
I am trying the following:
url='<my file full URL here>'
req = urllib.request.Request(url=url)
response = urllib.request.urlopen(req,timeout=120)
data=response.read().decode('utf-8')
PyScript doesn't play well (actually, doesn't play at all) with most existing Python libraries that handle HTTP requests (requests, httpx, urllib). Take a look at the PyScript documentation on HTTP requests here for guidance. It's a great walk-through on making HTTP requests in PyScript using pyfetch, a Python wrapper of the JavaScript fetch api.
One quick warning about the documentation. Like PyScript itself, the documentation is a work in progress. In the link above, there's a reference to the py-env tag. That has been deprecated and it doesn't look like they've updated that part of the documentation. The functions of the py-env tag have been subsumed in the py-config tag. More on that here.
UPDATE:
As a framework under development, PyScript is going to be a moving target for a while. Specific to your case, the documentation on http-requests (How to make HTTP requests using PyScript) was actually updated just this morning (11/8/2022). I'll refer you to that page for the code. One very important note, however. The code examples are written as though they are being run in an updated local development environment. When you point to the remote PyScript version to use, it matters which one you select. Your code points to <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
, which is perfectly reasonable -- it is, after all, the suggested release. The code example in the documentation, however, will not work with 'latest'. It will, however, work with 'unstable' (<link rel="stylesheet" href="https://pyscript.net/unstable/pyscript.css" />). When running this code using the 'unstable' release, it also appears that you have to run it in a live server. The point is workable solutions are going to be hit and miss for a while. What works today may not work next week.
Related
I'm using react.js, and I'm trying to integrate lucky orange into my web app. Where should I paste the javascript snippet?
As most analytics, you should parse their javascript sample last of the <head> tag on your index.html. It doesn't matter which framework you are using as it will wait for the loaded event to be triggered.
From luckyorange documentation :
Paste your tracking code into your page's source file just before the closing tag. Most websites re-use one file for common content (e.g. a page template), so it's likely you won't have to place the code snippet on every page of your website.
Also, you have legal obligation to mention your users about the use of cookies to track their use (always good to remind 😉)
I just tried up deploy my React app for the very first time and spend 6 hours on it. Very discouraged, as I have been trying to deploy a simple one page react app and I couldn't do it.
First I tried to deploy to heroku, then to gh-pages
I think I got some hints as to the culprit from chrome dev tools. When I look at the sources tab, it looks like the browser is expecting what I put in the browser URL bar to be the actual names of the files in my file tree.
For instance, I was using react-router, and I had a route called /users/:id/dashboard. So let's say the full app was http://myapp.com/users/:id/dashboard.
The Error I kept getting, probably over 500 times, was error 404 meaning not found. This means that the browser was looking for a file called myapp/users... when in fact, users was just simply a route. In other words the only entry point was supposed to be http://myapp.com/.... and anything after that should have been manipulated by the script file.
Anyways... this was a terribly frustrating experience to say the least. My app works perfectly in development, but in production mode error 404 is my enemy. I could really use some good resources for increasing my skills in this arena. Something that has to do with how a server serves up files, how the browser interacts with assuming what files will be served based on the URL, etc.
I appreciate it so much. Thanks for the help.
Since some time google officially depreceated ajax crawling scheme they came up with back in 2009 so I decided to get rid of generating snapshots in phantomJS for _escaped_fragment and rely on google to render my single page app like a modern browser and discover its content. They describe it in here. But now I seem to have a problem.
Google indexed my page (at least I can see in webmastertools it has) but when using webmastertools I look at google index-->content keywords it shows non processed content of my angularJS templates only and names of my binded variable names e.g. {{totalnewprivatemessagescount}} etc. The keywords do not contain words that should should be generated by ajax calls when Javascript executes so e.g. fighter is not even in there and it should be all over the place.
Now, when I use Crawl-->Fetch as google-->Fetch and render the snapshot what google bot sees is very much the same as what user sees and is clearly generated using Javascript. The Fetch HTML tab though shows only source without being processed using JS which I'm guessing is fine.
Now my question is why google didn't index my website properly? Is there anything I implemented incorrectly somewhere? The website is live at https://www.fightersconnect.com and thanks for any advice.
Our team is constantly working on an angular application, and every week or 2 we update it with new features or correct some bugs that came out.
We are using a C# backend with webservices.
QUESTION: When we update the application on the server, we sometimes (this doesn't happen all the time) get the problem that user is still seeing the old HTML and functionalities. What is the way to solve this?
I didn't find this on google, maybe I'm not looking for the right terms,
any help is appreciated.
Users have to clear their cache to get the new version of the application.
What you are seeing are cached copies of the JS files (possibly HTML partials too).
When the browser parses the HTML page, it makes the request for getting the JS resource and looks at various information before deciding to retrieve either the cached copy (if any) or whether to query the server again.
You can find some extra details on the Google fundamentals on HTTP caching
A solution I have been adopting myself is to set the cache headers to cache the file for a very long period, and then use tools in the build to version the file either on the filename or with a request parameter.
I have used grunt-cache-breaker and found it to serve well for this purpose. I know there is a gulp equivalent too
The most common way to make sure cached versions of your javascript aren't used is adding the version as a parameter in the reference to the script like so:
<script src="/app.js?v=v1.0"></script>
I tried to access the documentation pages for AngularJS:
http://docs.angularjs.org/tutorial
http://docs.angularjs.org/api/
But I noticed that the script links are broken and the page gets also broken because of that.
Is there any alternative resource for the interactive documentation?
Note
It seems that with the exception of the home page, which uses 1.2.0:
Request URL:http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js
Request Method:GET
Status Code:304 Not Modified
the links are broken on most of the pages of the official website.
Request URL:http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js
Request Method:GET
Status Code:404 Not Found
There's also an entry in the official issue tracker: http://docs.angularjs.org/ referring to a non existent version of angular from google CDN.
Every bit of documentation you need is in the Angular source code:
Angular methods are very well documented. For example, if (like the comment) you wanted to view the docs for ng-switch. You can go to:
src->directives->ngSwitch.js
That's give you all the documentation, usage examples and more plus the relevant source code which is worth reading.
You can also go to /docs/ for the actual documentation but it's not as nice imo :)