#web-development
2 messages · Page 12 of 1
I might be proposing something a little above what you feel ready for. it doesn't feel super complex to me, but I've sorta got the benefit of 5/6 years of passively absorbed web application design info
I've got all of about a month
these are all just recommendations that I think would make your ultimate objectives done to pass, but you don't need to take them if they sound too ambitious
as it stands your design sounds functional, just not as secure as you would like
I mean, it sort of makes sense. I just feel like I would have to have the whole, two player complication figured out, that seems difficult as is
like, two people connecting together in a game
anyways, thanks
I hope some of what I said helps a little, when others are available later I'm sure they'll have additional recommendations
Hi !
On my off-hours I've been trying to wrap my head around web dev + python.
Can anyone here explain how Flask and React/Vue would interact in a simple app?
I want to create a website for my discord bot. I want users to be able to login with their discord account and I want to grab their id and servers they are in. How can I do this?
Oauth2 and the discord API is what you're looking for @wary mantle
Oke..
I'm using python social auth's steam openid with flask-login to handle authentication/logging in and saving to mariadb with sqlalchemy. I have several different projrcts all using the same setup and I'd like to unify them by using one database for users data.
The user database would contain the following tables linked with foreign keys to the user table: user, roles, profile core, profile project1, profile project2, etc.
This way a user can login on whichever site the same way as before but the sqlalchemy user model would have a different binding and database so they can share information.
So my question is what's the best way to handle the user model? I was thinking have a separate models.py to maintain with the users / roles table. Should I include the profile/site specific tables in this external file as well for simplicity?
anyone familiar with postgres?
if it's a question specifically about postgres, it may be better to ask in #databases. other than that, don't ask to ask, just ask :)
Hello guys, I'm running into a problem on my socket application:
My server receives data from admins, and then broadcast it to all clients connected.
The problem is, It looks like it is "storing" the past data, for example:
Server-> THIS IS A HUUUUGE MESSAGE
Client has received-> THIS IS A HUUUUGE MESSAGE
Server-> tiny msg
Client has received -> THIS IS A HUUUGE MESSAGE tiny msg
Is anyone familiar with it?
Sorry, it receives: tiny msg THIS IS A HUUGE MESSAGE
How exactly do people create a new 'session' for each person visiting a site
to prevent the mixing of variables
@gritty locust would need to see your code
@sour heath probably with a framework that does it for them, but what you'd do is give each client a unique id (e.g. in a cookie, or appended as a URL parameter) and use that as a key to something like a dictionary containing session data
whatever you want to put in it
idk
hm
multiple server processes?
assuming I get all this storing of data and such working, how am I supposed to know when the person has logged off?
well
if they log off directly, there will be a log off page
otherwise just have an expiration date, maybe pushing it back whenever they have continued activity @sour heath
at that point, you purge the session data when they log off (make sure you can't ever reuse the key), or periodically purge all expired ones.
Well, not exactly a login sort of thing, I meant when they exit the page
I'm also not sure how to prevent the same person from being in the db several times
well, you can't. just have an expiration
also, it's not necessarily bad to have the same person in the db several times
sessions aren't users
I could also store that data somewhere to process it, cool
Well, the session key would be randomly generated
I get what u mean
Just will have to do some fancy stuff with sql
Do any of you use Pyramid?
if form.validate_on_submit():
flash(f'Account created for {form.username.data}!')```
what does that code mean
it is in flask
look at the top of the file, flash should be imported there somewhere, that or there is an import * check the docs of that module for the flash function and you will know
@native tide
np
@polar wasp Thanks, I "fixed it" just sending spare data after the right one, for some unknown reason it works.
hey guys
does flask have a post voting method or feature I can use?
I'm looking for a vote ranking system similar to whats used on reddit or imgur
you are thinking a lot too high level of flask
its a microframework, its built so you can build frameworks and stuff on top of it
what you are expecting is far too specific
oh... well do you know of any plugin or something I could use for that?
I'm learning flask at the moment, so I'm just trying to get a handle of whats possible
nope, i guess you could google for one but it shouldnt be too hard
youll have to build an endpoint for voting
and that somehow inserts stuff into a db
well, I found a reddit clone using flask, so I guess I can scavenge the feature from that later on
by the way, how much would it cost to hire a developer to make a site with basic similar features as imgur?
so, text/img downloads, content management system, user logins, etc
is it possible to make render_template change the url?
i can't use redirect bc I want to pass in variables
@app.route("/search", methods=["POST"])
def search():
searchobj= request.form.get("searchobj")
query=request.form.get("query")
query="%"+query+"%"
if searchobj == "title":
result= db.execute("SELECT * FROM books WHERE LOWER(title) LIKE :query", {"query":query}).fetchall()
elif searchobj == "isbn":
result= db.execute("SELECT * FROM books WHERE LOWER(isbn) LIKE :query", {"query":query}).fetchall()
elif searchobj == "author":
result= db.execute("SELECT * FROM books WHERE LOWER(author) LIKE :query", {"query":query}).fetchall()
return render_template("results.html", result=result,query=query)
When im adding an h1 tag, it adds a margin?
@native tide you could probably make it change the URL using a HTML redirect on the page, if that works
otherwise no
not without JS
does anybody know of any good free web hosts?
i'm looking for something with ssh
any good resources for learning flask? I have been using python primarily for data analysis (hello Pandas :)). I have realized that data models tend to pushed as a web service in most projects. From what I have read, it's either Flask/Django. I have decided to start with Flask given how it breaks everything down. The closest to any knowledge of web dev is basic html
im getting A required parameter "client_secret" is missing when trying to login using linkedin with authlib
from the same author there's also a book, "Flask web development", edited by O'Reilly
I really liked them both
@prisma marsh I will check it out. What do you think of TeamTreeHouse as a learning platform as well?
can't really say, I don't have any experience with that, sorry
no problem
can someone here help me with authlib?
how can i get the profilke details after user authenticxates with the oauth?
i want to get the profile picture and email of user after they link their linkedin accounts
im using authlib
anyone? im really stuck
i tried
resp = oauth.linkedin.get('people/~?format=json')
but that just gives me
KeyError: 'token_type'
Hello guys, does anyone here have some experience with socket / client-server application programming ?
Looks like my client scripts are "going down" after x random minutes and are unable to reconnect.
!t g ask
Asking good questions will yield a much higher chance of a quick response:
• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
My clients script are going down after x random minutes, and are being unable to properly reconnect to the server.
The clients recv() data all time, the server always ping from 1 second to 1 second, the only time that I could see/log the exception it looks like it throws an error on recv but the server was not shutdown for even a second.
What could cause this type of problem?
i will not be able to magically tell you whats happening if you dont show me the code, as stated in point 3
@strange thorn It is too big to paste on discord so you can access here:
- Client code : https://www.protectedtext.com/zac08code
- Server code: https://www.protectedtext.com/zac08servecode
Free online encrypted notepad. Simple, no registration, no ads! Our unique security approach makes ProtectedText.com the most secure way to store notes online. Easy to use secure notepad that just works!
Free online encrypted notepad. Simple, no registration, no ads! Our unique security approach makes ProtectedText.com the most secure way to store notes online. Easy to use secure notepad that just works!
Password is 123.
Password: 123
Tell me if you're unable to access it.
i can see the code
but eh
the client script isnt really doing anything?
its just a function definition
nothing else
nothing gets executed etc
It runs on thread, the While loop is always on recv(), based on decoded data you can see that sometimes it calls a function ( for example: ProcessarOrdem(str_recv) )
The problem is: After some random time, recv() breaks (lose connection to server?), BUT even if it breaks, it re-define the socket on the exception and reconnects (when it is working fine), but looks like some time It cannot reconnect to server, even it being online and running fine.
how many threads of the client are you running?
It is initiated just one time.
so that isnt the problem
hm
the reason for you not getting error messages is very likely that you are skipping most of the errors in the server script
you should print them at least
do that and try again if you see error msgs
I've tried that, but it just standard erros like WinError 10054 or 10056 , connection closed or something like that.
comment the try excepts out so we get a traceback to the line where it happens then
There is a way to log it without the Try and Except? Because as I said, this happens randomly , it is being really trick to get the exception as there is times that this takes hours to occur.
There is a way to log it without the Try and Except? Because as I said, this happens randomly , it is being really trick to get the exception as there is times that this takes hours to occur.
there is the so called traceback module which allows you to generate a traceback like you would get it if you let the try excepts out
but logging errors without try except and without crashing is impossible
Ok, I will try that, thank you.
When im adding a div, the background does not go all the way down
anyone know how to use the same variable in a different flask route?
So I’m making a website using Django that I’ll be hosting in DigitalOcean. I’ve been reading about using an Amazon S3 bucket to serve static files for it. I understand that in theory it’s supposed to speed up load times. My question is, at what point should I start caring about those load times for a few files? The other websites I have created seem to load quickly even with all the (few)static files hosted locally so is it something I shouldn’t concern myself about with small scale projects?
@heavy holly hope you don't mind me asking, what resources are you using to learn data analysis?
@small knoll mostly Pandas/Numpy/Seaborn/Statsmodel
i did
It was working properly for me
I'm having problems with handlnig circular imports in Django ..
As an alternative to regular imports, I'm currently fiddling around with get_model
this throws the models aren't loaded yet exception though
Is there any way to work around this?
I need help working with the flask restful API and Postgresql
$$ Plus lucky charm included
🙄
Hey @keen plume
Asking good questions will yield a much higher chance of a quick response:
• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
Sure
That doesn't mean PM me
You haven't asked a question, how would we know if we're interested?
Okay, i'll do
I am working on a closed corporate network and I am not exactly sure about the http authentication method to use for requests, to login and scrape from data from this web resource. I am trying to use the requests module with python 3.6.5. every time I try to push my authentication I get a response off the session as 200 but I am not able to get the page I want, it remains the login page every time. I think this is because whenever I login to the web resource in a browser, once I enter my credentials, I get hit with an alert asking me to agree with terms of service. How can I format that in my post request?
Is there something I am doing wrong?
import requests
from bs4 import BeautifulSoup
with requests.session() as mySession:
url = 'https://login.mycompany.com/onesso/login.jsp' # Url where I login to authenticate myself
url2 = 'https://aboutyou.mycompany.com/' # Url where I go to scrape data
myHeaders = {'User-Agent': 'Mozilla/5.0 (Macintosh;'
' Intel Mac OS X 10_10_1) '
'AppleWebKit/537.36 '
'(KHTML, like Gecko) '
'Chrome/39.0.2171.95 Safari/537.36'}
myReq = mySession.post(url, auth= requests.auth.HTTPDigestAuth('USERNAME HERE', 'PASSWORD HERE'),
allow_redirects=True,
headers=myHeaders)
newReq = mySession.get(url2,
allow_redirects=True,
headers=myHeaders)
print (myReq.text)
print ("------------\n")
print (newReq.text)```
how can i use jenkins with localhost???
tried ngrok
but it's said not to be secure
also tried this
https://confluence.atlassian.com/bitbucket/tutorial-create-and-trigger-a-webhook-747606432.html
@stable summit Flasks "advantage" over Django are that you can approach the problem in a more bottom-up way rather than top-down. it comes with almost nothing, so you put in what you need. if you're building a smaller app, this is fantastic. if you're building a massive superapp, it might mean you have to do a whole lot of groundwork before you can start actually making the app.
django is great, too, if you're building something that needs all of the features it comes with right out of the box. if not, it might be overkill.
I don't really see them as competing frameworks.
they're just two tools for different jobs.
flask is much better for beginners, though, since you don't have to learn what ORMs, classes, data models, relational databases, migrations and so on are in order to write a simple app.
I'm not sure if it's the right place to ask, but has any of you tried to automate the renew of a wildcard letsencrypt certificate with a python script ? The acme-python api that comes with certbot does not seem to be able to handle wildcards certificates at the moment
If you're on Linux just dump it into a cronjob
Doing it with Python is not really efficient cuz Let's Encrypt provide an easy enough cli interface
@languid bison if you just want to automatically renew the certificates without any python, you can create a systemd timer or cronjob to do it. IIRC if you install certbot it's gonna automatically install a timer
@quartz maple do you have a question?
@meager anchor actually for wildcards certificates it's a bit harder, you need to edit a TXT record in your DNS in order to get a signed certificate from LE
and certbot isn't able to do such thing
@fossil patrol same answer as above, if it was a standard certificate yes a cronjob would be the easy way, but it's a wildcard certificate 😃
oh I see, I haven't used wildcard certs from LE before
Ah, I didn't read that it was wildcard
how would I assign canvas elements ids, so I can refer to them later in my javascript code?
canvas = document.getElementById("cvn");
ctx = canvas.getContext("2d");
var gradient = ctx.createLinearGradient(0, 0, 100, 0);
gradient.addColorStop(0, "#00FF00"); // add id "first"
gradient.addColorStop(0.5, "black"); // add id "second"```
so I can then do document.getElementById("first")
@deep cave the learning curve to get up and running with flask for small crud apps seemed non existent when I made a small project with it, it made me implement users/login system from scratch which isn't really the case in django but it was satisfying xD
How much interaction can you get between any of the web libraries (Flask, django, etc..) and php?
what do you mean by interaction between them
how can i use jenkins with localhost???
tried ngrok
but it's said not to be secure
also tried this
https://confluence.atlassian.com/bitbucket/tutorial-create-and-trigger-a-webhook-747606432.html
They are different softwares, you can request one from the other but there isn't much you can do to get them to work together
So theres no smart way of replacing tasks in php with python?
I guess you could call Python code from inside PHP by running it using exec or whatever to run a command

Now the real question is, why choose php over something like js or python
What does php offer that those dont
what do you think about sanic for small projects?
Did you have any experiences with it? If yes, tell me about them!
@olive wharf You wouldnt
PHP offers an incredibly large web dev ecosystem with very speedy solutions. I don't like the language any more than y'all do but let's not pretend it doesn't have legitimate uses
it doesnt anymore
that's a silly thing to say
Php has so much documentation and has been around for so long that it won't be going anywhere anytime soon
@meager anchor no.
from site import app
if __name__ == "__main__":
app.run()
``` this is my code. I am trying to get Gunicorn to propagate.
This is the error I am recieving: https://paste.pythondiscord.com/oqezomitic.py
Can anyone help with this receeding error?
I got it working.
But ,
● myproject.service - Gunicorn instance to serve myproject
Loaded: loaded (/etc/systemd/system/myproject.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2018-08-08 10:00:55 UTC; 6s ago
Process: 1565 ExecStart=/home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app (code=exited,
Main PID: 1565 (code=exited, status=217/USER)
Aug 08 10:00:55 KCWS systemd[1]: Started Gunicorn instance to serve myproject.
Aug 08 10:00:55 KCWS systemd[1565]: myproject.service: Failed at step USER spawning /home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn: No such p
Aug 08 10:00:55 KCWS systemd[1]: myproject.service: Main process exited, code=exited, status=217/USER
Aug 08 10:00:55 KCWS systemd[1]: myproject.service: Unit entered failed state.
Aug 08 10:00:55 KCWS systemd[1]: myproject.service: Failed with result 'exit-code'.
could be the possible cause
that sounds like a permissions problem, which i believe was identified half a century ago at this point.
so then what's the nginx file?
if you have your nginx vhost set up properly then you get a gateway error
502 bad gateway
403 sounds like your vhost is not set up properly
server {
listen 80;
server_name server_domain_or_IP;
location / {
include proxy_params;
proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
}
}
it WAS that
server {
listen 80;
mydomainname.ca;
location / {
include proxy_params;
proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
}
}
Now its that
mydomainname.ca;
thats not how nginx directives work
server_name mydomainname.ca;
im not gonna tell you my domain name am i?
that wasn't even what i was pointing out
it's obviously my actual domain
but if you don't want help, then alright 👍
I also have another one (thats old)
caled main
Does it need the ; at the end?
@meager anchor
got it,
Aug 08 10:16:01 KCWS systemd[1720]: myproject.service: Failed at step USER spawning /home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn: No such process
It's still saying that.
I don't see that as a permissions error, because of the fact that everything should be working JUST fine
volcyy was telling you to put server_name before your domain
Process: 1720 ExecStart=/home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app (code=exited, status=217/USER)
Main PID: 1720 (code=exited, status=217/USER)
I did...
server {
listen 80;
server_name domain.ca;
location / {
include proxy_params;
proxy_pass http://unix:/home/inteca-webmaster/myproject/myproject.sock;
}
}
Process: 1720 ExecStart=/home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app (code=exited, status=217/USER)
Inteca-Webmaster should have all perms to that directory as it owns that directory
But maybe it can't be accessed via web?
I'll fix it myself.
I have indeed done that.
I'm getting 502.
Getting error 502 now.
Can anyone help me?
gunicorn isn't running, so the proxy pass isn't working properly
502 means The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
Well the proxy pass is correct.
yes, but gunicorn isn't running
Should be, @meager anchor based on .service.
Aug 08 10:16:01 KCWS systemd[1720]: myproject.service: Failed at step USER spawning /home/inteca-webmaster/myproject/myprojectenv/bin/gunicorn: No such process
# systemctl status gunicorn
if it says "failed", "stopped", anything like that, it isn't
I’m back
However, note I’m on my iPad.
@meager anchor sir can you help me fix my problem?
you can probably not do much about it from your ipad
check what systemctl status is saying about gunicorn
Hey guys, how would I limit uploads on my server to like 5 uploads a minute
no
Then you would have to limit it by IP I guess
is there anything already done like this?
or would I have to find IP add a session timer
Most likely yes
thanks
@native tide you can use nginx's built-in ratelimiting if you want
and if applicable
ah my bad it's a python flask server
it's set up behind a reverse proxy though isn't it?
and I'm kinda low on ram
I have 1gb, back end is implemented in C to save memory
since I'm a hobo and don't want to pay
😄
@meager anchor I can use flask's ratelimiter tho
can do that. but nginx can also do it, and nginx receives the requests in the first place 😛
how much memory would nginx consume?
I forgot to say I'm already using 600mb ram for processing
i forgot how to read memory usage of a process 🙃
I'm on windows server 2016
nginx probably - oh
can nginx return http status codes?
say if I run nginx and I have like 10 users a second max
how much memory do you thin it would consume?
You're running windows on 1gb?
https://www.nginx.com/resources/wiki/community/why_use_it/ there's some "benchmarks" here
Testimonials from people using NGINX in the real world, under real load, serving real applications and websites.
That's brave
15% CPU and 1MB of memory to serve 11,500 requests per second. lmao I'm set
no problems
gonna have to turn of windows server 2016 gui
and turn off that anti-malware executable since it's a fucking ram eater, because I run all my shit in a sandbox
and yes a sandbox in a 1gb ram machine
does anyone know how i can deply a python app on a plesk vhost? using nginx+apache?
*deploy
@meager anchor I was looking at how I could implement everything
User attempts record -> nginx checks if uploads -> flask would have to check if the upload is legal -> increase nginx user ip related upload amounts -> return a custom error code that includes seconds that the user has to wait -> parse error code in JS?
I'm not sure if nginx can cache by upload body, check out what I linked earlier, you might be able to use that as a cache key
the why use nginx?
ah rate limiting
ok so I'm still a bit confused on how to limit user uploads to like 20 uploads/hour
ok I'm just gonna do this I'm gonna ratelimit a user to 2 uploads per minute , if they upload the incorrect stuff ¯_(ツ)_/¯
welp turns out I ended up doing it in python
so I'm checking how flask responds to files above the max size, so my browser sends an xhr request, then flask returns a 413 but my browser doesn't see the error code in the network
It’d say systemctl status gunicorn?
@quartz maple ?
someone please bless me with an answer
on the right hand side is xhr post request succeeded, on the left hand side is flask declining a xhr post
JS can't understand that it's a 413
TCP packet by the way
Welp turns out it's a giant issue at the httplib level so im fucked
Yeah its very hard to get an answer here.
Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 583, i n spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1 29, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 1 38, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, i n wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52 , in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 41 , in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 350, in i mport_app
__import__(module)
ImportError: No module named restart
[2018-08-09 06:04:35 +0000] [26957] [INFO] Worker exiting (pid: 26957)
[2018-08-09 06:04:35 +0000] [26953] [INFO] Shutting down: Master
[2018-08-09 06:04:35 +0000] [26953] [INFO] Reason: Worker failed to boot.
I restarted gunicorn,
as suggested
and i got that ^
I'm not sure if I restarted it correctly.
@neat nest ?
It looks so.
you ask terrible questions from devices you can't use to debug, what answers are you expecting, exactly?
that doesn't look like you restarted anything properly, notice the ImportError
I'm pretty sure you were told NOT to restart it
you don't need to restart gunicorn, you can tell it to reload and it will gracefully stop and start new workers, IIRC```
as per Volcyy
oh that's directed at someone else
even so, I can't find any record of anyone here telling you to restart it
did you take Volcyy's most recent recommendation? it's got nothing to do with restarting the service
root@KCWS:~# systemctl status gunicorn
Unit gunicorn.service could not be found.
...
.service looks familiar, can you think of anywhere else you've seen that?
I fixed it
Dw
I made a small, mistake.
Without noticing.
But thank you anyway @neat nest.
Fuuuuuuuuuuuuuuuuuck now Im going to have to tell my users that they shoule not upload a file bigger than 16mb imstead having an erroressage when they do
What happens if they do
My xhr doesn't get a response
But w/e problem is very low-level
Can't solve with python
Good news, @meager anchor I solved my issue.
I know you don’t care, but I just wanted to let you know.
just a question before I dive in "two scoops of django". Is the book still actual? Are the info written for version 1.11 still (somewhat) valid for django 2.x?
Best book on Django / flask?
real quick question about terminology - so discord and slack will display mini-previews for certain links pasted into chat, like YT vids or images. is 'unfurling' the correct word to use when describing this feature?
that is apparently what slack uses internally
i just can't tell if there's a more technical term for it
i need help with something
i made a text input box
and i want to do something like
if someone puts text in there
and leave
and come back
it should still be there
how would i go about doing that
@teal scroll You can do that completely client-side with JavaScript and local storage or cookies
@gaunt lava i think you're referring to embedding and its based on some graph tags, Open Graph maybe? i can't remember off the top of my head
I'm thinking of start working with web dev soon but don't know how and what to do.
What have y'all done and with what?
I know I wanna use Flask.
But the rest, I really dunno.
@winter hearth
Here's my procedure data i've been collecting
- Full tech list explained
https://codeburst.io/want-to-build-a-cutting-edge-data-app-heres-the-tech-to-do-it-2576658eff96
• Backend Language: Python 3
• Web framework: Flask and Flask-Restful
• Database: Postgres + SQLAlchemy + FlaskMigrate
• Server: Nginx
• Frontend Framework: React.js
• Frontend Data Management: Redux
• Frontend Asynchronous Requests: Redux Sagas
• Styling: Styled Components
• User Authentication: Auth0
• Package Management: Webpack
• Deployment: Multicontainer Docker to AWS with ECR and Elastic Beanstalk
- Full tech list explained 2 (python as well)
https://www.youtube.com/watch?v=s6NaOKD40rY
- 1 Going from an Idea to a Pitch: Hosting your Python Application using Flask and Amazon Web Services (AWS)
There has been a lot of noise about being a "full stack developer" recently. What does the full web stack look like for Python and how do you go about learni...
- 1 Going from an Idea to a Pitch: Hosting your Python Application using Flask and Amazon Web Services (AWS)
http://amunategui.github.io/idea-to-pitch/ (text)
https://www.youtube.com/watch?v=3HuYr6G2Z28 (video)
Machine Learning, R Programming, Statistics, Artificial Intelligence
Let's see how easy it is to transform an idea into a web application. This is for those who want to quickly pitch their application to the world without gett...
- 2 Connecting Vue and Flask using Axiom to handle requests from frontend to backend.
https://codeburst.io/full-stack-single-page-application-with-vue-js-and-flask-b1e036315532
-
3 NGINX
apache + nginx = 70%https://www.youtube.com/watch?v=SKmdIQqkfjI
nginx and MariaDB ( securing MariaDB )
https://www.udemy.com/advanced-python-flask/
https://www.quora.com/What-are-the-differences-between-nginx-and-gunicorn
In this video we will install and configure our Nginx web server and the MariaDB database server. See the whole lesson in the playlist “Deploying Flask Appli...
Learn to create scalable web applications that can serve millions of users using Flask, MongoDB and Amazon AWS
Nginx is a web server and reverse-proxy responsible for serving static content, gzip compression, ssl, proxy_buffers and other HTTP stuff while gunicorn is a Python HTTP server that interfaces with both nginx and your actual python web-app code to...
2.4 WSGI and how they work
https://stackoverflow.com/questions/4929626/what-are-wsgi-and-cgi-in-plain-english
additional resources:
https://stackoverflow.com/questions/46214132/how-can-i-combine-vue-js-with-flask
https://www.reddit.com/r/flask/comments/612ovo/pros_and_cons_of_flask_and_vuejs/
https://vuejsfeed.com/blog/full-stack-spa-with-vue-js-and-flask
https://secdevops.ai/weekend-project-part-1-creating-a-real-time-web-based-application-using-flask-vue-and-socket-b71c73f37df7
https://stackoverflow.com/questions/49773514/vue-front-end-flask-back-end-integration
I want to use Vue.js and Flask together: Vue.js for a dynamic front-end, and Flask for the back-end. How can I do that?
Vue.js full-stack single page application served over Flask microframework & a tutorial on how it was built
The full source code for this project can be found here and a live demo can be found here.
Below is my vue front-end build(npm rum build on vue-cli 3).
And below is my run.py file for flask back-end.
from flask import Flask, render_template
class CustomFlask(Flask):
jinja_options =
Sooo
I'm gonna save all you sent because sadly most stuff didn't make any sense rn.
Like
It did make sense but I don't understand how I would use the info.
Gonna keep on watching everything though.
@winter hearth have you ever done web dev before? maybe look into Django too
I havent thats the thing
django might be a bit more approachable , its what I started with way back in the day
heck, its what I'm using right now
django REST framework for an API and im getting Vue set up for the front
Django tends to be very hard to approach for newcomers
It's huge and has a prescribed way of doing things
how so? i mean i get that it comes with a lot of stuff
Yes I have seen some Django web development videos (tutorials) the thing is that it like. Was kinda weird I would say. I followed one and it like. Umm, I didn't do anything. Because all I did was change some true to false and reload the "website". Like then he started talking about different apps. It just felt like I was downloading someones discord bot and choosing the cogs I wanted to load but in a weird way.
but the docs are really well written and actually learning the stuff makes web dev a breeze
but yeah, i learned django way back in '07
im willing to concede that things have changed since then
the official tutorial isn't bad
I can understand it's a very powerful framework. But I dont really feel like what I did was anything. It was like climbing a wall instead of a mountain. (Flask I guess) Like a wall is straight up so I have to smash all this info in my head until I'm at the top of the wall (learning curve, and know what to do) but with the mountain (I think lol) I can learn a small thing as I go through.
Let me try to the official tutorials then.
I'll be back when I've don't that. It's pretty late at night rn so maybe in one 11 hours (lol)
Ty guys
good evening! i've been working with python for a while now (super hack) for web based automation etc. Mainly Selenium. I use Docker to run most of my scripts, but i use a modified program for checking in with southwest airlines automatically. I am trying to make the commandline a webpage front-end. On that front-end it allows me to input the 3 command line items (confirmation,first,last) and then the script runs and sleeps until the time for checkin. During that sleep, I want the webpage to show the "sleeping" running python scripts..
any tips?
and also the ability to run new instances of the python script
Hello! Does anyone have any experience with Wordpress and Python? How can one incorporate Python in there etc.
E.g. using the Dash module to add neat interactive graphs on one's page
i dont have experience with it but wordpress is a PHP platform which is already pretty solid for itself you should maybe try to achieve stuff with PHP if you already have the platform @mossy hamlet
Hm, that'd probably take too much coding and learning, as Dash is a superb library and can create functional GUI with a few lines only. I do not know anything about php either.. The idea atm is to get interactive graphs up on the site.
I heard about some options on how to get Python scripts to WP. It seems to be very complicated still. But I was given some guidance and will look into <iframe> now.
Hi pepol, so I was using vue for several of my projects and kinda wondering if it has a chance at become The One True Framework (haha classic) for view bindings over react. I really like it but on the other hand react is the big boys and big ecosystem and seem to be the prime candidate as a go to thing. So maybe I should submit to it too. 🤔 Any vue enthusiasts or webdev "zeitgeists" here to illuminate me?
I don't think Vue is going anywhere, but neither is React
Heyo, so I'm a bit on stuck on how to go about doing something. I have some items such as badges and buttons that are one colour and when I recieve some data I want them to change to a different colour, problem is that when I remove the class and add the new one there is a slight delay between the items changing colour, is there anyway to make it do it all at once?
Each object doesn't have the same class either.
Asking good questions will yield a much higher chance of a quick response:
• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
I have 3 different items, a card header, a badge and a button, when the page loads they have classes "cardheader-black", "badge-black" and "btn-black" respectively, I want to be able to change the "black" part of each class to "purple", using removeClass and addClass doesn't do it at the same time so it's slightly noticeable, I'm asking is there a better way to go about doing this?
Hopefully that makes a bit more sense, sorry
could you show the code you are working with please?
$('#CardHeader' + id).removeClass('cardheader-black').addClass('cardheader-purple');
$('#Badge' + id).removeClass('badge-black').addClass('badge-purple');
$('#Btn' + id).removeClass('btn-black').addClass('btn-purple');
That's how I'm currently doing it
But I'm sure there's a better way, just trying to figure out what
I have a question about flask development, is there any way to use flask to change or add text to a text box? not manually but by python
I'm trying to make my chatbot web-based so I can use it on any device i wanted to any where
So I need to return data some how
Please tell me if there is a better way to do this
I have googled for quite a bit and I could only find the opposite, sending data from the text box to the server (post)
you're going to need to write some JavaScript for the browser side that communicates back and forth with your Flask server
websockets are the latest and greatest way to do this kind of thing, there's also paradigms like AJAX that've been around for a while
alright
hm, i wonder, if i want to code a webinterface for my bot .... discord.py-rewrite ... would be flask or django better?
probably flask, imo.
ok and how would i best code the interface. like, i wanna be able to access it remotely. now, should i run the app (integrated http server) or should i upload the webinterface somewhere? if iuploadedit it wouldnt run together with the bot and im not able to ... simply call methods etc. hm on the running bot
do not run flask projects with the development server it comes with, that's for development and testing environments.
http://wsgi.readthedocs.io/en/latest/what.html i believe this will be useful. (i never knew WSGI was python-specific o.o)
ok thanks a lot
😃
should i code with or without templates? oO
and is there anything like a default theme that looks good? or something because im usually not much into web development
templates will be needed yes. as for a 'theme', i think you might want to look into a CSS framework to style your web page if you don't want to create the CSS yourself.
ok and how would i make the webinterface communicate with my bot? oO
you'd probably have to have a coroutine running in your bot's event loop so that it can somehow listen/poll for incoming requests from the interface application.
hm ok thats much work for a simple thing like just displaying in which guilds the bot is in
or maybe the bot can regularly write the statistics to a file which the site reads from in the same interval.
that's likely the easiest way. probably not the best way though.
hm maybe i shouldnt code a webinterface yet
btw, in pycharm how do i "create new project from git" without closing my current project?
not sure, would be better to ask in #tools-and-devops though.
ok thanks 😃
Hey guys I'm ready for deployment, Ive got a domain, IP/DNS configured flask code optimized which production server do I use, I'm on windows server 2016
windows server :^)
Yeah I had to
Why
Windows malware analysis
@tame viper are you telling me windows has a defualt server that I can configure with flask?
Holy shit that's some black magic
iis
nah, i just automatically bash windows when i get the opportunity to. :D
What
@tame viper kinda had to use windows server though since malware analysis on windows
Rip
Would have used centOS/Debian
yeah i get that, i'm half-joking :P
So what server should I use my python app with?
Flask app, any suggestions?
I'm thinking waitress
a common setup for flask apps is nginx+uwsgi but I dunno if that runs on windows
Nginx is on windows so is uwsgi
Use them
i'm trying to scrape IP addresses from those 'free proxy list' sites, anyone advise me on some documentation or guides that will help me?
using python preferably.
requests-html is all you'll need
this is the wrong channel, btw
Use one of the general help channels
@near ridge For future reference 
Mah bad
All good, man
Hi, I have requests slow down on production with a Flask back-end, is that normal?
Some requests take a few seconds other take 15+ sec
randomly
Any idea why I'd get this behavior?
that sounds like a problem specific to your situation and not a common bug
what are you using to serve it?
gunicorn
have you already checked gunicorn's logs for anything unusual?
hey guys anyone here knows how to store a variable on the server side in javascript?
i found this var mJSVariable = <%:myServerSideVariable%>;
that's very particular to ASP.NET, not quite as straightforward if you don't have a specialized framework for it
i'm using flask
standard fare is make an AJAX request to some route you define in your Flask application
trying to get autofresh to work
yup, AJAX is the way to do that
is the problem so simple that I can't find anything on this
you make your own HTTP request to a Flask route that doesn't provide a full page, but instead just provides enough information for you to update the page
does it work across different pages?
cause I want to trigger an auto refresh on another page
not on the current page
like I press submit info
than the database would update, the admin would receive a signal somehow telling the browser to refresh
I'm not sure something like that requires JS at all. that's just a regular form submission, isn't it?
You could just poll the database from the admin site every so often and check if it’s changed
does that require php?
but like... this doesn't require any polling, this is just a regular submission. am I completely off base in thinking the page ought to reload if the form action is the same route?
uh.... different route
the end-user is just submitting something to the database, then returns to the 1 st page of request info (not the workspace)
the workspace route where the admin is, is separate
I think that's what u were referring to
so yes I think the http request thing is part of the answer, I just need to figure out some how.
So i manage to send a http request but separating the function failed it. It can refresh the page where the code is place but not on a different html page.
workspace.html <script> function update() { if (httpRequest.readyState === XMLHttpRequest.DONE) { if (httpRequest.status === 200) { location.reload(true); } else { alert('There was a problem with the request.'); } } } </script>
request.html
(function() {
var httpRequest;
document.getElementById("submit-info-button").addEventListener('click', makeRequest);
function makeRequest() {
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
alert('Giving up :frowning: Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = update;
httpRequest.open('GET', 'workspace');
httpRequest.send();
}
})();
</script>```
is there a reason why this doesn't work? I mean the httpRequest.open('GET','workspace') should connect the two functions right?
this is not very related to python, IM JUST WONDERING... are you allowed to sell a wordpress website?
yes, as long as you follow the license
I am having trouble configuring two databases with flask and psycopg2.
I am not using any ORMs
I dont know how well I can phrase my question so that people can understand
is it a Flask question or a #databases question?
It is a flask question because the database is working
why two databases?
I want to use one database for running tests and another one for storing data
because tests has teardown I dont want it to tamper with the actual data
and what seems to be the issue that you're encountering?
Its either my configurations or something I am missing.
As it stands, I can only use one database
When I try to configure, it only picks on db
I mean, you should probably only be connecting to one at a time in any case
are you trying to connect to both at once?
No
How do I connect it one at a time
I am trying this
if 'test' in sys.argv:
database = os.getenv('DATABASE_NAME')
else:
database = os.getenv('DATABASE_TEST')
@neat nest my problem is how do it tell the database connect that now, tests are running
well... how do you normally connect?
class DbConnection():
"""Initializes connection to the database and executes queries"""
def __init__(self):
# load credentials from environment
if 'test' in sys.argv:
database = os.getenv('DATABASE_NAME')
else:
database = os.getenv('DATABASE_TEST')
# database = os.getenv('DATABASE_NAME')
user = os.getenv('DATABASE_USER')
password = os.getenv('DATABASE_PASSWORD')
host = os.getenv('DATABASE_HOST')
# uses credentials from the environment to connect to the database
self.conn = psycopg2.connect(
f"""dbname={database}
user={user}
password={password}
host={host}""")
# saves every database execution aumatically
self.conn.autocommit = True
self.cur = self.conn.cursor()
# performs database queries
def query(self, *args):
self.cur.execute(*args)
@neat nest this is my db connection class
looks like a nice piece of code. what's not working about it?
When I run tests using pytest, I find the wrong database being populated
you're running it with test in your argv somewhere?
Lol. I dont know what that actually means just copied it from stack overflow..
ah
understanding the code you write is usually essential to fixing it
I understand that
But basically, i just need a way to tell the connector that know tests are running, please choose a different database name
right. so what mechanism can you use to identify when tests are being run? because using the Django method probably won't work in your case
on account of you not testing with Django
clearly
really what ought to be happening, I think, is you pass a dbname to the class
instead of the class finding it itself
There is one way using configurations
oh?
oh okay. db name to class
mnh..
I could try that
I was hoping to use the different working environment configurations to communicate to the db
but that is here I was stuck
I mean, you can, this just doesn't seem like something the db init should be handling itself
discover the configuration outside of DbConnection and pass it in
also you should rename it DBConnection because it looks much nicer
db_connection = DBConnection(host, user, password, name)```
or something to that effect
it won't on its own, it just makes more sense to do it that way
you said "There is one way using configurations" but never elaborated. is there a way to tell when you're testing?
Okay
I will examine your feedback. Thanks
import os
class Config():
DEBUG = False
TESTING = False
SECRET = os.getenv('SECRET')
class Production(Config):
DEBUG = False
class Development(Config):
DEBUG = True
class Testing(Config):
TESTING = True
DEBUG = True
app_config = {
'development': Development,
'testing': Testing,
'production': Production
}
This is my config file
That is where I am stuck
This is where I am loading testing configurations fr the app
use a different settings file per environment instead of class thing
then you can have a common file with shared settings and change what you need
e.g.
myproject/settings/common.py # <- you star-import from here
myproject/settings/dev.py
myproject/settings/test.py
myproject/settings/prod.py
that's one way to accomplish it, I'm personally a big fan of django-environ
Thanks
looks enough clear to understand?
I am afraid I do not understand it at all
yep, not gonna pretend that I have any idea what that's about
With a bit of context, maybe? Else I feel maybe sliders, and more spacing (if it's a phone display). I'd hate to misclick those tiny buttons
Okay, I have a problem, I have my backend as python and my frontend as js and I have to do some stuff with jquery to edit the template which has to take place in the frontend. This is an issue as the only way to pass information from the front end to the backend is through jquery requests (that I know of). I have a card game and I have to replace images with more images but this requires making a flask url that passes the player hands which means its accessible to anyone, how could I fix such a thing. I've asked this before but I want to attempt to get a clearer understanding.
the data I need it for is for moving the cards from one section to another
I was considering just storing the player objects in the sql database I'm using for the sessions, but the player could simply use the debugger tool and track the vars that happen to be storing the data pulled from it
jquery has a move function but then I wouldn't know how to call a function in the python when a card is 'clicked' as that would require a url which means more chance of someone screwing with it
I am having some trouble with nginx I have made a new conf file for deploying a django app and I can't seem to get nginx to point to my project. I can present my current config file or any other files if need be just let me know.
One second
is the current config file
if you want to see the nginx.conf let me know
is django running?
also :8000 is the dev server
you should be using something like gunicorn
75 MB client max body size is also ... quite a lot, do you want people to OOM your server or something
I plan on reducing it I wanted to stress test but I can't get the page to load anyway
and I can use gunicorn
I cant get nginx to proxy guni
and django is currently not running
server {
listen 443;
listen [::]:443;
root /var/www/sharpweb.me.uk;
index index.html;
server_name sharpweb.me.uk www.sharpweb.me.uk;
location / {
try_files $uri $uri/ =404;
}
ssl on;
ssl_certificate /etc/letsencrypt/live/sharpweb.me.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sharpweb.me.uk/privkey.pem;
}
https://www.sharpweb.me.uk/upload.php
I am trying to get nginx to access my upload.php file
Which i use for sharex
But i get a 404 error
Anyone know whats going on?
Dang
it's never
That link
check your nginx logs
in /var/log
the file missing so maybe your rootfolder param is wrong
@unreal dagger if django isn't running then nginx won't proxy anywhere
unless you have something else listening on 8000
location / {
try_files $uri $uri/ =404;
}
Isn't it try_files $uri=404 ?
I might be wrong on this
location = /upload.php {
try_files $uri $uri=404
}
try_files $uri $uri=404;
try adding that
dunno then
nop
ok
server {
listen 443 http2 default_server;
listen [::]:443 http2 default_server;
root /var/www/sharpweb.me.uk;
index index.html;
server_name sharpweb.me.uk www.sharpweb.me.uk;
location = /upload.php {
try_files $uri $uri=404;
}
ssl on;
ssl_certificate /etc/letsencrypt/live/sharpweb.me.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sharpweb.me.uk/privkey.pem;
gzip on;
gzip_types application/javascript image/* text/css;
gunzip on;
}
My problem is getting upload.php to show for sharex
If anyone knows why i get a 404 error, lemme know ;D
Resolved my issue
@brave mantle root option stops any other file from not giving 404 except the index.html file?
Ok. So it's not that?
I just don't understand why my website loads fine, yet /I/ and upload.php give 404 errors
You don't even have PHP configured
You should have a location / block though
And you don't
The location block you already have should be that
Although your try_files is wrong too
It should be $uri $uri/ =404;
Repz said to try not doing that
No, you should have that
It applies to everything that doesn't have a more specific location block
Yes
You are assuming I have base knowledge
I didn't put 2 and 2 together
Got it now sorry xd
Trust me, I've learned to not assume that :P
No, I'm on mobile, having a date with a bowl of noodles
@brave mantle why doesn't Nginx like Apache do this sorta thing by default ?
Apache doesn't do it by default either
PHP worked for me straight away
Nginx does support PHP, but you do have to install php-fpm
Which is, honestly, a much better option than mod_php
Ok
I'll remember that
Would /I/ be making a 404 error if it had a Apache access file?
Cause I don't understand why that would give a 404 otherwise
@brave mantle even if I didnt have support for PHP, it shouldn't give a 404 error should it?
It gives a 404 because you don't have an index file in there
And indexing is disabled
Afk, busy
Smh why didn't I think of the word indexing in my searches
That should make finding the answer easier
Thanks a bunch gdude
I have been here for 2 hrs
Try to get this to work: https://medium.com/@jgefroh/a-guide-to-using-nginx-for-static-websites-d96a9d034940
But, my website: (sharpweb.me.uk)
Is showing the default page only
Any ideas?
Never used that before but maybe one of your config files is not pointing to the directory with your public web pages...
Have you restarted your web (httpd, apache, etc) service since configuring it?
I always find when something is not quite right it's usually a simple issue. 😃
@brazen dune if I typed in somthing wrong, Nginx should give you a error
🤷
if there is something wrong with your config file you can use "nginx -t"
and it should tell you if there is something wrong with the conf file
That's cool. Thanks
Well I'm 16
And I had a website
So sure it is :D
Mine wasn't free. But in theory you could make a free one
i think im too late to develop man everyone started developing good stuff at 12 i started basic python at 14 and still is on basic python
how was yours not free?
if you could homehost?
Homehosting just ain't as secure
I only started coding in January and I'm doing really well so far
i guess i aint just home learning im relying too much on education at offical places
scaleway offers basic hosting for ~$3/month so it really doesnt cost much to make a public website and get your own server nowadays
scaleway super cheap
we want free tiers forever
Azure offers a dedicated server free for. 12 months I believe
It’s not a high tier server but it’s something.
Aws has a similar offer. So that’s like 2 years of hosting there
Yes
My website now won't even connect
But if i use the default one, it does
I am using certbot to do my keys
How do i check that certbot is running, and that no other program is using my https port?
root@Sharp:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Also, this isn't testing my files at all
hmmm turns out uWSGI isn't windows compatible
any ideas on how to serve my flask app?
This returns a bad gateway
Following this guide: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04
@shrewd sand nginx -t does test your files. it doesn't test whether they are doing what you want them to, it tests whether nginx can read and understand them, and whether that configuration would work or not
having a program figure out what you want to do with it is probably very hard if not impossible
show your nginx config
bad gateway means nginx tried to proxy but the upstream server didn't respond
@meager anchor it didnt check anything in sitesenabled
Or did it?
Its now 404
server {
listen 443 default_server;
listen [::]:443 default_server;
root /var/www/sharpweb.me.uk;
index index.php index.html;
server_name sharpweb.me.uk www.sharpweb.me.uk;
location / {
try_files $uri $uri/ =404;
}
ssl on;
ssl_certificate /etc/letsencrypt/live/sharpweb.me.uk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sharpweb.me.uk/privkey.pem;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Just trying to get sharex working
won't the first location block match first?
hmhmhmmm, but the guide doesn't have the try_files over there
@meager anchor does it not?
Great
Any other ideas?
Just cause I can't test tonight
Just anything else you think could be wrong
ah, I was wrong, the php location block will take priority
the rest seems fine, haven't worked with fastcgi personally apart from fcgiwrap
but you haven't tried anything new yet have you 🤔
@native tide serve it in windows using wsl
If I'm not mistaken he has 1
where would be the best place to store user-uploaded files for a flask application?
as in, in the project itself or are you speaking about URLs?
well, with my flask app people can upload files and they get a download link and whatnot, but where exactly should the files be stored on the server side?
the filesystem? Probably depends on your needs
just somewhere out of the way of the app itself?
yeah
i store my static stuff in /var/www/website.com/...
could use e.g. /var/www/juanssite.com/media
@tame viper how are you using the files?
think of it like a file sharing thing (it's similar to that, anyways)
I see then you can probably just save them in your filesystem
yeah okay
@tame viper you should probably run them through a compression algorithm first though
yeah i have
for filesharing that sounds kinda important
yup
imo use django it’s so much easier to manage
i like how django has a lot included
it's just a matter of opinion, yeah :D
holy fuck working with scss in pycharm pro is a damn dream
+1
File watcher?
yeah so it automatically makes the css file when it detects the scss changes
well
I remember him talking about it
I could just check for myself 😄
But we have a script for that in the Gitlab repo so I'm not sure if it's actually a feature
oh yup, i could have answered that. it's very useful.
Yeah it does, I use it
Hey guys, I'm a little lost here. So I'm trying to data bind JSON data from my Python file to my HTML file to determine a school's name, url, city, state, zip, and number of students. I'm trying to connect it to different HTML tags (ie. h2, span, etc), but I'm having trouble. If you're interested in helping me, I'd be eternally thankful as this project has incredible importance. For ease of reading, I'm copy/pasting what I wrote so far:
import requests
import json
import urllib2
api_key = "key_string_here"
url_base = "https://api.data.gov/ed/collegescorecard/v1/schools/"
# Makes a get request to collegescorecard API
r = requests.get("https://api.data.gov/ed/collegescorecard/v1/schools/?"
"school.operating=1&2015.academics.program_available."
"assoc_or_bachelors=true&2015.student.size__range=1..&school."
"degrees_awarded.predominant__range=1..3&school.degrees_"
"awarded.highest__range=2..4&id=240444&api_key="
"key_string_here")
school = r.json()
for item in school:
url = ("https://api.data.gov/ed/collegescorecard/v1/schools?"
"school.operating=1&2015.academics.program_available"
".assoc_or_bachelors=true&2015.student.size__range=1.."
"&school.degrees_awarded.predominant__range=1..3"
"&school.degrees_awarded.highest__range=2..4&id=240444&"
"api_key="+api_key+"&fields=school.name,school.school_url,"
"school.city,school.zip,school.state,2015.student.size")
req = urllib2.Request(url)
response = urllib2.urlopen(req)
response2 = response.read()
json_data = json.loads(response2)
params = {
'api_key': api_key,
'school.name': 'University of Wisconsin-Madison',
'school.school_url': 'www.wisc.edu',
'school.city': 'Madison',
'school.state': 'WI',
'school.zip': '53706-1380',
'2015.student.size': '29579'
}
resp = requests.get(url=url_base, params=params)
data = resp.json()
hey guys does anyone have experience with the waitress server
I'm trying to serve my flask app
It gets hosted but I always get a URL not found
none of my routes are being found
app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
app.config['MAX_CONTENT_LENGTH'] = 8 * 1024 * 1024
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
serve(app,0.0.0.0,8080)
@app.route('/hello')
def hello():
return 'Hello, World'
is the 404 actually being returned by waitress? are you actually visiting the /hello route? which reverse proxy are you using, if any?
I am not using any reverse proxy, I don't know if the 404 is being returned by flask or waitress
I suspect flask
yes I have tried visiting the /hello url
still get a 404 which leads me to believe it's a waitress problem
@meager anchor sorry for the late response
so you have no other http server running on :80 or :443, that's all waitress. correct?
okay
and yes I have no other HTTP server running at port 8080
I have a feeling that the serve(app,0.0.0.0,8080) gets evaluated before the route gets added
are you telling me to server after all my defs
👍
hey volcyy if I've configured my DNS
and my domain I'd have to host with 0.0.0.0 to get my domain to start working
What are you using? flask or django
waitress serving a flask app
I've got my namecheap domain pointed to my AWS instance
I don't use flask, but is there like an allowed_hosts = [] anywhere?
try looking @ http://flask.pocoo.org/docs/1.0/tutorial/deploy/
yeah I'm on a production level server
now I'm having trouble getting my domain to connect
How long ago did you create the dns
5 days?
should be enough
ok, are you using an a record
an a record??
lemme tell you what's on my record set
What kind of record are you using
make an A record like this https://gyazo.com/024f0b7a77a361a6d8fcd86a636a4bb4
@native tide turns out it's not dns problems
my external IP is not actually connected to my internal IP
👌
Hey I don't suppose anyone here has knowledge of aiohttp?
I'm sending a JSON request to a service (an airconditioner) and sending the request through aiohttp doesn't seem to work. The request gets sent and a response comes in through wireshark but the aircon seems to just ignore the command.
I have tried sending it with the requests package, that works. The only real difference I can see between the two is that requests uses keep-alive while aiohttp doesn't.
I have tried using a TCPConnector to enforce keep-alive but that doesn't seem to work. Kinda out of ideas here....
show us your code for sending the request?
Looking at wireshark, there's a whole pile of odd TCP errors after the push, there's a TCP out of order packet sent by the server, then a whole pile of Dup ACK packets sent, and retransmissions sent back
async def _send_command_async(self, command: str, data: Any, callback: Callable = None):
try:
body = json.dumps({command : data})
async with self.session.post('http://%s/%s' % (self.device_ip, command),
timeout=Controller.REQUEST_TIMEOUT,
data=body) as response:
await response.text()
response.raise_for_status()
if callback:
callback()
except (asyncio.TimeoutError, aiohttp.ClientConnectionError) as ex:
self._failed_connection(ex)
(same thing happens without the timeout BTW, and I've tried removing the user agent and content type headers and it makes no difference)
that looks like it won't be using the right headers
instead of using json.dumps() to jsonify that dict, just try attaching it directly to the post request with the json keyword arg?
yeh tried that, no dice
Tried it with and without Content-Type
This is the sync version:
def _send_command(self, command: str, data: Any, callback: Callable = None):
# Do this synchonously. For some reason, this doesn't work with aiohttp
body = {command : data}
url = f"http://{self.device_ip}/{command}"
try:
with requests.post(url,
timeout=Controller.REQUEST_TIMEOUT,
data=json.dumps(body)) as response:
response.raise_for_status()
except requests.exceptions.RequestException as ex:
self._failed_connection(ex)
raise ex
These are the actual packets as captured by wireshark:
POST /SystemMODE HTTP/1.1
Accept-Encoding: gzip, deflate
Accept: */*
Content-Length: 22
Content-Type: application/json
Host: 10.0.0.107
User-Agent: Python/3.6 aiohttp/3.3.2
{"SystemMODE": "auto"}
POST /SystemMODE HTTP/1.1
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 21
Host: 10.0.0.107
User-Agent: python-requests/2.19.1
{"SystemMODE": "dry"}
huh.
Have played around with content type and user agent, doesn't make any difference
yeah your sync version wouldn't be sending that Content-Type json header either, it seems
and still it works
The only difference is Connection: keep-alive
The response for both is code 200 = OK
that's all you get in response?
Yep, except for the whole pile of odd TCP packets which I don't really know how to interpret
sounds like kind of a pain in the ass API to work with :P
yeh it is 😦
But I'm writing a connector for home assistant so that will be good when done. Then I can automate my central heating better :p
heating / cooling
And more to the point, it gets me programming again which I've not been into for a while.
Is there any way to force aiohttp to use keep-alive?
the way you already mentioned would be my approach.. though I suppose you could just manually set that header if you really wanted to make the requests look the same in terms of header data
I was thinking of doing that. I might try that next
doubt it will help, but worth a try
shrug yeh. I suspect aiohttp will barf because you're putting the wrong header in
IDK if I can be bothered mucking about with it anymore, might just do it synchonously. Just seems a waste to be sitting there pointlessly using a thread waiting for IO
I mean ultimately both of these libraries are probably using urllib to actually send the request. If you really wanna figure this out, you should probably whip out your debugger and walk through the requests, listen to some variables, and figure out exactly what's different.
would they be however? I dunno... I could do some digging I guess. Maybe some kinda odd low level TCP issue or something.
It feels like the device itself is the problem, which clearly I've got little ability to fix
yeah
but there's nothing about async in and of itself that would fuck with it
it's gotta be the request
No! totally
I suspect the device manufacturers only ever used keep-alive, so it's untested otherwise
and a request is a request. if it works sync, you can get it working async if you just figure out what's different and change it
that's the only thing I can think of really
but I am also stumped as to what that might be
Maybe the device just doesn't like having TCP connections closed or something?
you seem to be using aiohttp correct, fwiw.
yeh that's what I think
async coding is kinda fun to get your head around
Back when I was doing this kind of low-level coding selectors had only just been invented, Java had only just brought it out
good thing to get into.
home automation is fun. I just bought a house, I'm gonna be doing some more of that myself soon
We used to just use thread pools
yeh 😄 get into home assistant, it's a lot of fun
I tell my google home "OK I'm going out" and all the lights turn off and the garage door opens
super fun
and the TVs and Radios turn off
it's like living in the Jetsons :p
Anyhow, gonna head home, ttfn
server {
server_name search.sharpweb.me.uk;
location / {
return 301 https://google.com/;
}
}
Why does this redirect not work?
I have my website server bracket underneath
You have no listen directive
If i have multiple listens, does that not create a conflict?
No
server {
listen 443 default_server;
listen [::]:443 default_server;
server_name search.sharpweb.me.uk;
location / {
return 301 https://google.com/;
}
}
So thats fine?
Cool
Why are you using default_server
Idk
well perhaps you should learn what that does
also, 443 is HTTPS, and you have no SSL configuration there
Is there a way to allow the same ssl for all in less lines?
Instead of copying and pasting all the time
What? No, you should have a separate cert for each (sub)domain ideally
Ok
@brave mantle i wanna try and get a hastebin server setup with all of this. Do you know a good tutorial i can follow?
Nope, but read the hastebin docs
Web-dev 😦
@deep cave hey I discovered using an old version of aiohttp<3.0 works correctly. Must be a bug in it I guess
huh, interesting. glad you figured it out.
@deep cave well... I didn't figure it out.... Next step is to check out aiohttp and see if I can fix it in there and then submit a patch :p (urrgghhh rabbit-hole)
I think I've found the issue by looking at the diffs... I think
hey guys I'm having trouble setting up https with nginx & Waitress the WSGI server
when I try to go to my domain I just end up at the welcome to nginx page
here is my nginx configuration
serve(app, host='0.0.0.0', port=80,url_scheme="https")
thanks in advance btw 😄
Hi guys I was hoping to get a python web developer for a partnership
Anyone up for it?
DM me
not sure if this is the best place to ask but would comparing the time between heartbeat requests and acks be a viable option for measuring the network latency?
@mighty crow maybe, but python may not be the best language for that
what might be?
@pale relic Python is more than okay, unless he wants to measure nanosecond-wise latencies
Well for extremely precise timing python is not what you want, but I guess if it is ok to have estimates, python should be more than ok
Unless you are into HFT you never have such requirements
or doing some precise science experiment
ultra-high precision wouldnt be important for me
im just aiming to track any spikes that might occur
interesting
well ignoring the language choice is the idea sound?
i wonder if pinging it instead would make a difference
Well I guess you couldn't
*could
Do that, however, there are better options available
But as a consept there is nothing wrong with that
does anyone use spyder for flask development?
