#web-development

2 messages · Page 9 of 1

brittle copper
#

The thing is that it works as in it adds a new app with my user information

#

Instead of registering it into the contrib.auth app

#

I'm just gonna use this as a separate app called user and put my models in another app and just remove the Group all together

native tide
#

did you migrate when you set AUTH_USER_MODEL?

brittle copper
#

I deleted the database

#

And did my first migration with auth user set

#

Yup went with that

#

Thank you for trying tho :D

native tide
#

I installed Django because it was bugging me. Couldn't get it to work :D

#

one possible solution might be templates

gritty carbon
#

Hey guys, any suggestion for good and free course and/or tutorial for Django? I'm doing one from official site at this moment, but i could use something more detailed and begginer friendly 😃

meager anchor
#

I found the one on the site to be pretty detailed..

#

@gritty carbon what issues did you face when reading through it?

gritty carbon
#

@stone vine thanks mate will check them out for sure
@meager anchor i don't understand templates syntax and why we are passing values to them in form of dictionary, that's the first thing for example. I have no problem recreating steps in that tutorial but i don't feel that i'm really understanding all concepts

meager anchor
#

Templates get values in dictionaries because that's the simplest way to associate a variable in the template with a value from your python code

boreal tree
#

Hello fellas. I am in need of some asistance with SOAP ws and python. If someone knows anything about it, please, would you kindly help me? This is my case.

#

I'm trying to send an XML envelope file to a SOAP WS using python

#

Notice that the WS i want to consume is public and has the following tree structure.

#

So i just want to consume the sendBill method from that WS

#

for this i have tried about 3 different libraries. Being zeep the most recommended on StackOverflow and the one that looks like might solve my problem.

#

But with zeep, it looks like all i need to do is sent the variables to the parameters the method requires. Which is actually wrong, since the XML envelope you get when analyzing that public ws looks like this.

#
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.sunat.gob.pe">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:sendBill>
         <!--Optional:-->
         <fileName>?</fileName>
         <!--Optional:-->
         <contentFile>cid:872654575379</contentFile>
         <!--Optional:-->
         <partyType>?</partyType>
      </ser:sendBill>
   </soapenv:Body>
</soapenv:Envelope>
#

but the ws actually wants a xml like this

#
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://service.sunat.gob.pe" xmlns:wsse="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <soapenv:Header>
        <wsse:Security>
            <wsse:UsernameToken>
                <wsse:Username>20100066603MODDATOS</wsse:Username>
                <wsse:Password>moddatos</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <ser:sendBill>
            <fileName>20100066603-01-F001-1.zip</fileName>
            <contentFile>my-zip-file-encoded-base64</contentFile>
        </ser:sendBill>
    </soapenv:Body>
</soapenv:Envelope>
#

so i need to send an entirely XML to that ws instead of just filling the parameters from the method i want to use

#

for that i have found this example (from StackOverflow) on python

#
import requests
url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'text/xml'}
body = """<?xml version="1.0" encoding="UTF-8"?>
         <SOAP-ENV:Envelope xmlns:ns0="http://ws.cdyne.com/WeatherWS/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
            <SOAP-ENV:Header/>
              <ns1:Body><ns0:GetWeatherInformation/></ns1:Body>
         </SOAP-ENV:Envelope>"""

response = requests.post(url,data=body,headers=headers)
print response.content
#

the thing now is. How do i select the method i want to use from the WS i want to consume?

#

Btw i am using python 3. Not python 2.

#

If i adapt that example to my case, i would get something like this

import requests
url = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'
# headers = {'content-type': 'text/xml'} if needed
headers = {'content-type': 'application/soap+xml'}
body = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://service.sunat.gob.pe" xmlns:wsse="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soapenv:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>20100066603MODDATOS</wsse:Username>
<wsse:Password>moddatos</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ser:sendBill>
<fileName>20100066603-01-F001-1.zip</fileName>
<contentFile>my-file-encoded-on-base64</contentFile>
</ser:sendBill>
</soapenv:Body>
</soapenv:Envelope>
"""

response = requests.post(url, data=body, headers=headers)
print(response.content)

#

still tho, how do i select the method i want to use?

native tide
#

(don't know much about SOAP), but I'd take a look at zeep again

#

I'd be surprised if it can't do what you need

#

how did you get zeep's xml? with create_message?

boreal tree
#

sadly i don't seem to find it. So i'm asking every where if someone could help me.

native tide
#

you can't find the generated xml?

boreal tree
#

No, i used requests on the second example

boreal tree
#

sadly, no. That's for creating the XML

#

i already did that

#

i have an xml created

#

i want to send it to a SOAP ws

#

but i want to send it to an specific method inside that ws

native tide
#

by using requests or zeep?

boreal tree
#

any of them would be useful

#

or any other library

#

😛

native tide
#

have you tried sending the xml with requests with a POST request like this:

#

(I'd still probably go back to zeep if this isn't working out)

boreal tree
#

yeah, that's the same example i wanted to use. But, how do i define the method i want to use from the ws?

native tide
#

maybe Weather.asmx? ?

boreal tree
#

wait is it? let me see

native tide
#

or if you try something like this:
"For example, suppose the StockServices Web service from the preceding procedure contains a Web service method called GetQuote; the Web service method accepts a stock symbol as a parameter, returning the price as a double-precision floating-point number. Enter the following HTTP-GET request in the browser's address bar to test this method:

http://<servername>/apppath/StockServices.asmx/GetStockQuote?tickerName=MSFT "

#

so instead of GetStockQuote you'd try sendBill

#

was there some kind of error in the response?

#

oh that's only a service

#

I'd try this then

#

and if this doesn't work, I'd go back to zeep :D

boreal tree
#

D:

#

a friend of mine helped me and said he would do this on zeep

import zeep
from zeep.wsse.username import UsernameToken

import base64

with open("20100066603-01-F001-1.zip", "rb") as f:
    bytes = f.read()
    encoded = base64.b64encode(bytes)

wsdl = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'
client = zeep.Client(wsdl=wsdl, wsse=UsernameToken('20100066603MODDATOS', 'moddatos'))
print(client.service.sendBill('20100066603-01-F001-1.zip', b'encoded'))
#

But it doesn't return the same error as when sending the same data with SOAPUI

#

so, it is not working correctly.

#

but with that, at least i now know how to call an specific method.

native tide
#

what does this print: print(client.service.sendBill('20100066603-01-F001-1.zip', b'encoded')) ?

boreal tree
#

Just a reminder. That all data i've been using is for testing. It is suppoused to give an error, but it is supposed to give the same error on SOAP Ui as on the IDE i'm using. (which is PyCharm)

native tide
#

hmm

#

:D

boreal tree
#

that prints this

#
zeep.exceptions.Fault: El archivo ZIP no contiene comprobantes - Detalle: xxx.xxx.xxx value='ticket: 1529609364082 error: Validation File count error'
native tide
#

just so I understand. you get the correct error on SOAP Ui?

boreal tree
#

and SOAPUI prints this

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
   <soap-env:Header/>
   <soap-env:Body>
      <soap-env:Fault>
         <faultcode>soap-env:Client.2335</faultcode>
         <faultstring>El documento electrónico ingresado ha sido alterado - Detalle: Incorrect reference digest value</faultstring>
      </soap-env:Fault>
   </soap-env:Body>
</soap-env:Envelope>
#

yeah i get the error i was expecting on SOAP UI

#

but not on PyCharm.

native tide
#

do you also send the zip file via SOAP Ui?

boreal tree
#

yep

#

encoded on base64

#

SOAP UI gives you that option, which is what i also need to do.

native tide
#

where can I see the arguments sendBill requires?

boreal tree
#

If you need more details, just tell me. I'm can give you as much info as i am able to.

#

that's on the documentation for that ws

#

it's like this

#
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://service.sunat.gob.pe" xmlns:wsse="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <soapenv:Header>
        <wsse:Security>
            <wsse:UsernameToken>
                <wsse:Username>20100066603MODDATOS</wsse:Username>
                <wsse:Password>moddatos</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <ser:sendBill>
            <fileName>20100066603-01-F001-1.zip</fileName>
            <contentFile>my-zip-file-encoded-base64</contentFile>
        </ser:sendBill>
    </soapenv:Body>
</soapenv:Envelope>
#

and not like the one you can get by inserting that ws on SOAPUI

#

according to the documentation

#

it's on spanish. But the example for using that ws is on page 17

native tide
#

how do you run this code?

boreal tree
#

the given example on the documentation?

native tide
#

no, yours with zeep

boreal tree
#

i run it on PyCharm

native tide
#

if you comment out the print line, do you get any errors?

boreal tree
#

nope

#

😮

native tide
#

what's in that zip file?

boreal tree
#

an xml

#

with test data. Not real

#

Do you want it? I just adapted it from another example on of the example given on the documentation

native tide
#

is it large?

boreal tree
#

hmmm about 320 lines of xml code

native tide
#

are there many tickets?

boreal tree
#

hmmm... what are tickets? 😛

native tide
#

don't really know. I assumed you have them defined in your zip file, because 'ticket' is mentioned in the error

#

can you add this line after your print:
import sys;sys.exit()

#

and paste if there are any errors

boreal tree
#

like this?

native tide
#

yeah

boreal tree
#

still, it's not reading what's inside my zip

native tide
#

yeah, but are there any errors?

boreal tree
native tide
#

no other errors?

boreal tree
#

nope

#

i just undertood the problem itslef

#

the ws is not reading the zip file

#

or what's inside the zipfile

#

but that's what's strange, i tecnically am doing the same thing on SOAPUI and it works

native tide
#

is your zip file and your file with the code in the same directory?

boreal tree
#

yeah

native tide
#

oh

#

can you try:

print(client.service.sendBill('20100066603-01-F001-1.zip', encoded))

insted of:

print(client.service.sendBill('20100066603-01-F001-1.zip', b'encoded'))
#

(and delete sys stuff)

boreal tree
#

ok

#

same error

native tide
#

just to be sure, rename the bytes variable. it's a reserved keyword in python and it shouldn't be used as a name (though, it's not likely it's causing errors in this case)

#

rename to to something like: zip_bytes or anything you like

#

I'd try adding this to the code:

from zeep import Client, Settings

settings = Setting(strict=False, xml_huge_tree=True)
client = Client([what_you_have_now], settings=settings)
#

after that I'm running out of ideas unfortunately

#

@boreal tree, also make sure you have the username and the password in the correct order (and you've posted the username and the password several times, I'd urge you to change the password at least)

boreal tree
#

I'm sorry i didn't respond, i was absent. The username and password are test data, is not real, i put random numbers to match an example just like it is on its public documentation.

#

As i said before, the xml has test data and it's supposed to return an error on the ws. My goal is to have the same error on Pycharm. That's how i will know i could send data correctly.

native tide
#

ok

#

so one last thing I would try is with settings

boreal tree
#

i am currently trying that.

native tide
#

hope it works, because beyond that... no idea :=)

boreal tree
#

Thank you so much for your help @native tide I know you must be tired of helping me but sadly it did not fixed the problem.

On the other hand. I wonder if print is the best way to get the response form the ws. Maybe the problem is the way i want to retrieve the data?

native tide
#

it's not a problem :)

boreal tree
native tide
#

the print here in this case doesn't matter

#

it's just there to show you the response

boreal tree
#

i get the same error message.

zeep.exceptions.Fault: El archivo ZIP no contiene comprobantes - Detalle: xxx.xxx.xxx value='ticket: 1529616712333 error: Validation File count error'
#

which is a response the ws is giving me

native tide
#

I think this is the same error as before, right?

boreal tree
#

it says the zip cannot be validated

#

yeah

#

it's the same error

native tide
#

in SOAP Ui, do you have everything on one screen?

boreal tree
#

yep

native tide
#

can you screenshot it and show me?

boreal tree
#

the value on content file is not what i sent

#

i wrote that so it could be understandable

#

lol

native tide
#

the value of content value is base64 encoded gibberish?

boreal tree
#

what i actualy do is, right click on that field, then "insert data as base64" then select the .zip i need to sent

native tide
#

ok

boreal tree
#

you can try it yourself if you have soapui

#

do you want the .zip?

#

its an xml adapted from an example on the ws documentation

#

with fictional data

#

that's why it returns an error, but it returns an error of "invalid value"

#

i expect to have the same error on PyCharm

#

but can't have it

#

:/

native tide
#

can you paste the faultstring on the right?

#

yeah, because the error you are seeing in pycharm is not the response

boreal tree
#
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
   <soap-env:Header/>
   <soap-env:Body>
      <soap-env:Fault>
         <faultcode>soap-env:Client.2335</faultcode>
         <faultstring>El documento electrónico ingresado ha sido alterado - Detalle: Incorrect reference digest value</faultstring>
      </soap-env:Fault>
   </soap-env:Body>
</soap-env:Envelope>
native tide
#

can you also show me what are xmlns:ser and xmlns:wsse in full (on the left)

#

you can copy just the one line

#

have to go now

#

gl

#

if you figure it out, let me know :)

boreal tree
#

thanks @native tide

You mean the Soap request xml? if so. It's this one

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://service.sunat.gob.pe" xmlns:wsse="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <soapenv:Header>
        <wsse:Security>
            <wsse:UsernameToken>
                <wsse:Username>20100066603MODDATOS</wsse:Username>
                <wsse:Password>moddatos</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <ser:sendBill>
            <fileName>20100066603-01-F001-1.zip</fileName>
            <contentFile>my-zip-file-encoded-base64</contentFile>
        </ser:sendBill>
    </soapenv:Body>
</soapenv:Envelope>
boreal tree
#

now I'm analyzing both base 64 array bit. to see if maybe both are different.

#

the one generated with SOAPui and the other generated by script

boreal tree
#

i'm using the following code in order to get the base64 code i'm sending to that ws

from zeep import Client, Settings
from zeep.wsse.username import UsernameToken

import base64

with open("20100066603-01-F001-1.zip", "rb") as f:
    bytes = f.read()
    encoded = base64.b64encode(bytes)
settings = Settings(strict=False, xml_huge_tree=True)
wsdl = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'
client = Client(wsdl=wsdl, wsse=UsernameToken('20100066603MODDATOS', 'moddatos'), settings=settings)
# print(client.service.sendBill('20100066603-01-F001-1.zip', b'encoded'))
# print(client.service.sendBill('20100066603-01-F001-1.zip', encoded))
print(encoded)
#

it prints this

b'UEsDBBQAAAAAAJB71UykoJUx5j4AAOY+AAAZAA...AEcAAAAdPwAAAAA='
#

while SoapUIs converter just returns this after generating the base64 code

#
UEsDBBQAAAAAAJB71UykoJUx5j4AAOY+AAAZAA...AEcAAAAdPwAAAAA=
#

Isn't the b' affecting the base64 code in any way?

native tide
#

b'' is a Python thing, I think

#

I'd say those are the same

boreal tree
#

yeah i checked. Both codes are literrally the same

#

except for the b' at the begining and the ' at the end

native tide
#

b'' indicates that its bytes

polar wasp
#

just do print(encoded.decode()) # which looks kind of nonsensical, but what's being "decoded" here is ASCII

#

I've actually always been kind of annoyed by the fact that b64encode returns bytes instead of a string

boreal tree
#

you mean like this?

native tide
#

its .decode()

boreal tree
#

oops 😛

#

ohh i see

#

now it returns the same as on soapUI

#

i'll try and see if that works

#

sigh*

#

it indeed want a byte-like type 😦

#

So, my concusion is that, the problem is not the encoding of my .zip on base 64. I'll be back on the previous error for now and keep on looking for solutions.

boreal tree
#

Ok,I found out 1 guy had the same problem. But he says he resolved it cuz the encoding of the zip was actually just econding the xml inside the .zip .Would this be the case for my problem as well? Does the encode method from base64 bypass the .zip and just encode the .XML? Does anyone know something about it?

#

if so, then why was the base64 code generated on SoapUI the same base64 code i got, generated on Python?

native tide
#

you can try it out

#

just unzip the file and encode it

#

I don't think it bypassess the zip

brittle copper
#

Lemme ask you guys something @brave mantle and @deep cave You guys are the only prof python devs I know

#

And you roughly know what I can and can't write

#

And I thought I was in off topic god damn it

#

I was gonna ask if I'd have any chance at a python webdev job with my current skills

brave mantle
#

@brittle copper maybe

#

depends how much on-the-job training they'd provide

brittle copper
#

So at most I can be an intern?

#

Kind of

deep cave
#

get better at working with others, and focus on readability. you probably have the skills to solve python webdev problems but you lack essential teamwork and readability skills.

#

being able to solve the problems is really the easy part.

brittle copper
#

I mean I just am memimg around when I write code but I think I can write readable code

#

I mean at least I think so

deep cave
#

probably. it's not rocket science

#

just following best practice and style rules.

#

but do more collab. with flake8.

#

and uh

brittle copper
#

Hmm, I'm gonna actually try to finish a full project and put it on github and apply to a couple entry level jobs

deep cave
#

another tip

#

python webdev is often full stack-y

#

get over your fear of linux.

#

work with databases

#

master git

brittle copper
#

Yeah I can handle basic javascript and html and I am okay as long as there is an ORM for the database

deep cave
#

don't expect an ORM

brittle copper
#

Git, I'm still learning

deep cave
#

learn sql

brittle copper
#

Linux is just too scary to dive into

#

Dql? Is that like a database?

#

Oh

#

xD

deep cave
#

sorry. mobile.

brave mantle
#

linux isn't scary

brittle copper
#

dw :3

brave mantle
#

for web work, it's often less scary than everything else

brittle copper
#

There are just so many of them

deep cave
#

you don't need to learn them all

#

just learn one well enough to be comfortable.

brave mantle
#

learn a debian, learn a red hat

#

that's about it

deep cave
#

get a vps or something with like centos or ubuntu server and put up shit on it

brittle copper
#

learn the debian

#

Or a debian based one?

#

Like would ubuntu do it? xD

meager anchor
#

my server runs ubuntu, and i've learnt a lot from it

#

ubuntu is debian based

brittle copper
#

Oh so just ubuntu is okay, nice :D

#

get a vps or something

#

Imma try AWS

#

I'm just too scared

#

xD

deep cave
#

fuck aws

brittle copper
#

lol why

deep cave
#

or.. I mean.. it's a valuable tool

#

but it's a terrible vps choice for a beginner

boreal tree
#

so, in theory, by doing this, i am encoding my .xml instead of my .zip, which i can confirm that happening since the base64 code is different from before. But i still get the same error. @native tide

from zeep import Client, Settings
from zeep.wsse.username import UsernameToken

import base64

with open("20100066603-01-F001-1.xml", "rb") as f:
    bytes = f.read()
    encoded = base64.b64encode(bytes)
settings = Settings(strict=False, xml_huge_tree=True)
wsdl = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'
client = Client(wsdl=wsdl, wsse=UsernameToken('20100066603MODDATOS', 'moddatos'), settings=settings)
# print(client.service.sendBill('20100066603-01-F001-1.zip', b'encoded'))
print(client.service.sendBill('20100066603-01-F001-1.zip', encoded))
# print(encoded.decode())

zeep.exceptions.Fault: El archivo ZIP no contiene comprobantes - Detalle: xxx.xxx.xxx value='ticket: 1529696554236 error: Validation File count error'
brittle copper
#

Oh

deep cave
#

digitalocean or scaleway would be much better.

brittle copper
#

Hmm, welp I'll try to do it that way then I mean aren't the commands and stuff the same

#

Since it is the same linux distro

deep cave
#

scaleway has a 2 euro vps which is quite powerful.

#

2 euros per month

brittle copper
#

Yeah that's not a problem

#

But aren't they the same as long as they use the same linux distro inside

deep cave
#

yes, mostly

#

package manager and file locations vary

brittle copper
#

Like don't they work like I have a remote computer and put my os in it and do whatever I want

deep cave
#

and the internal workings

#

but just like with programming languages - learn one and the rest are easy

brittle copper
#

Nice

#

Welp I still have to finish a project to show at applications to prove that I actually learn stuff but I'm definitely gonna try my chances :3

deep cave
#

yeah, you should bring a github with something on it

#

it's a huge advantage over those who do not.

#

and you know, once you start fucking with a VPS you can suddenly pick up 20 of those buzzwords in a year

brittle copper
#

I am already probably gonna ask a ton of stuff when I am actually gonna deploy my very first website

#

I only ever used py manage.py runserver

#

lol

deep cave
#

soon you'll be able to say you know about nginx, gunicorn, postgresql and rethinkdb, you know ubuntu server and systemd and you know travis-ci and github or gitlab and ci-runners and you know linters and you know the basics of a bash script and before you know it, you're one of those guys with a list of tech on their resume

brittle copper
#

Okay I've almost heard all of them

#

Except ci-runners

deep cave
#

it's just travis on gitlab

#

basically

brittle copper
#

Oh, okay I've heard almost all of them :D

#

Nice

deep cave
#

I put one of these stupid lists on my resume

#

and people eat that shit up

brittle copper
#

Oh damn xD

#

Okay I know js, python, django, jinja

#

Nice

#

xD

deep cave
#

so what you want is just a project on github / gitlab that showcases these techs. then when you brag about knowing all this shit in an interview, you can actually back it up with a URL that shows you used them in a project.

#

even if it's a stupid project

strange thorn
#

can i say i know LLVm when i have written a hello world in LLVM?

deep cave
#

you could, but I don't know if you should :P

strange thorn
#

k

brittle copper
#

I mean I had a working website already but I avoided putting it on github

#

And am rewriting it

#

With proper tools

deep cave
#

I make it a point to only mention tech that I've worked with for long enough to not feel intimidated by.

brittle copper
#

Instead of shitty one liners

#

Hmm, only python and django then

deep cave
#

like, I have C++ experience too but it scares the shit outta me so it's not on my list :P

strange thorn
#

i dont feel intimidated by LLVM

#

i just hate it

native tide
#

@deep cave, thanks, I learned something new about what to put in my CV :=)

brittle copper
#

Welp thank you lemon, I'm gonna apply to some stuff and as soon as I get a job I'm gonna treat you a döner :3

deep cave
#

sounds good

native tide
#

actually, techs I'm not intimidated by has become my main section :D

#

@boreal tree, can you try:

print(client.service.sendBill('20100066603', encoded))
#

I've no idea why the error would be about ZIP when you're not sending a zip file

boreal tree
#

the thing is the ws expects the name of the zip and then the zip encoded on base64.
*If i give it the .xml encoded i get the same error as when i send the .zip
*If I send an incorrect .zip name it returns an error saying the name of the zip is incorrect
*If i send the zip encoded with its name written wrong. it returns an error saying the name of the zip is incorrect

#

The ws, IS recieving my request, but it's failing who knows why. so up until now i have 2 theories

#
  1. The ws is poorly programmed and it just doesn't work properly most of the time.
  2. The ws has some kind of security that doesn't allow requests from unknown senders. So SoapUI is trusty but doing your own code on an IDE just isn't
native tide
#

ok, so at least there's another error when you send the wrong name

boreal tree
#

yeah, that's why i know the ws is at least recieving my data

native tide
#

yeah

boreal tree
#

so... i'm pretty much f*cked right? xd

native tide
#

yesno

#

:D

#

can you try your code again (the original 'good') code

boreal tree
#

The sad part about this is that. I've read on forums that the ws provider doesn't actually respond for this errors. If i try to contact them, they will probably ask me to reboot my modem. That's what people said the ws provider told them.

native tide
#

and see if the ticker number goes up everytime you get the error?

#

:s

#

ticket-

boreal tree
#

oh right the ticket

#

let's ssee

native tide
#

tickets could be how they track errors

boreal tree
#

yeah the ticket number vary

#

1529697587691
1529698118169
1529698145386
is what i got from 3 consecutive requests

native tide
#

yeah, that's probaly how they track them

#

am

#

is there documentation for the service

#

?

boreal tree
#

well i'm planning on doing a documentation on how i got till this point.

native tide
#

it's possible you could find the anwser there

boreal tree
#

yeah, there is documentation for the ws

native tide
#

it's in spanish?

boreal tree
#

i'm looking for it rn

#

yeah, it's on spanish

native tide
#

sorry, can't help you with that :)

#

first, I'd look specifically for the spendBill method and see what you can find out from that

#

then I'd go look for filetypes and if there are any errors associated with them

boreal tree
native tide
#

no hablo espanol, unfortunately :)

boreal tree
#

that's what the ws does, basically

native tide
#

maybe there are some details in the documentation that might give you a clue what could be wrong

boreal tree
#

I hope.
I'm reading it again

native tide
#

also are you 100% that the error from SOAP Ui is the 'correct' one?

boreal tree
#

yeah. I'm sure about that one.

#

Since it's analyzing the xml and telling me the field I put wrong data, has wrong data.

#

:P

#

before that I had other kind of error from other wrong data I put there. As I said before all data on that xml is fictional. For now I just gotta make sure i send my data through my custom code on python.

native tide
#

and the error from your program complains about the whole file?

boreal tree
#

it says

 Validation File count error'
#

wait i think i found my problem

native tide
#

?

#

do tell

boreal tree
#

nvm tried to send another xml inside the zip to see if it still gave me the same error (hoping for it to not) But it did give me the same error. So i got nothing.

#

¯_(ツ)_/¯

native tide
#

:D

#

can you run the program with python 2?

boreal tree
#

i guess, but i got to install python 2 😛

#

i'll try it tho

native tide
#

which OS are you using?

boreal tree
#

win10

#

64 bits

native tide
#

_<

#

don't know if I'd bother. I don't think it will change anything

boreal tree
#

i'll still try it tho. ty @native tide ~

#

If i get to make this to work. I'll do a documentation, but if I don't... i'll still probably do it. lolz

native tide
#

you know what I'd try before that?

#

use create_message to see the created xml

boreal tree
#

like this?

from zeep import Client, Settings
from zeep.wsse.username import UsernameToken

import base64

with open("20100066603-01-F001-1.zip", "rb") as f:
    bytes = f.read()
    encoded = base64.b64encode(bytes)
settings = Settings(strict=False, xml_huge_tree=True)
wsdl = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'
client = Client(wsdl=wsdl, wsse=UsernameToken('20100066603MODDATOS', 'moddatos'), settings=settings)

node = client.create_message(client.service.sendBill('20100066603-01-F001-1.zip', encoded))
print(node)
native tide
#

not sure. I have to check the docs

#

does it work?

boreal tree
#

nope, same error

native tide
#

?

boreal tree
#
zeep.exceptions.Fault: El archivo ZIP no contiene comprobantes - Detalle: xxx.xxx.xxx value='ticket: 1529702201943 error: Validation File count error'
#

i have found a github project from other person for consuming this ws, but it's on c#. I'll check and try it out. Maybe there's something i missed.

native tide
#

like this maybe:

node = client.create_message(client.service, 'sendBill' , fileName='20100066603-01-F001-1.zip',  contentFile=encoded)
#

client.service.sendBill() actually sends whatever you have

#

so that's no good if you wan't to inspect the created xml before it is sent to the server

boreal tree
#

your code returns this.

<Element {http://schemas.xmlsoap.org/soap/envelope/}Envelope at 0x20e17b42308>
native tide
#

can you show me the whole stacktrace?

#

sorry, got to go

boreal tree
#

don't worry, i got to go too rn 😛

loud walrus
#

hey

#

which is better flask or django

#

and is there any good ides for web development that are compatible with either of these frameworks

meager anchor
#

which is better flask or django ah yes, the "vim vs emacs" of python

#

flask is usually recommended for smaller projects

#

its a lot more customizable

#

and gives you a lot more freedom for doing stuff

loud walrus
#

lol

meager anchor
#

django is batteries-included, brings e.g. migrations, tests, and whatnot out of the box

loud walrus
#

and I absolutely hate html

meager anchor
#

so "which is better"? neither, they're both amazing frameworks

loud walrus
#

is there any way to like

#

any recommendations getting into html and css?

#

I never understood how it really works, even when I try to learn, creating sites with even a login page seem confusing.

meager anchor
#

i found w3schools pretty good

loud walrus
#

its not that I dont know how

#

Is there a way I can use a wysiwyg ide?

#

like bootstrap studio or something?

#

or would that be pointless?

meager anchor
#

html really isn't that hard

loud walrus
#

like so I can make a half decent control panel

#

I always found actual GUI work easier

#

cause coordinates make sense

#

but like bootstrap and all that make absolutely zero sense.

#

in other words, what would it take to make a login page using firebase

#

I need to have the user sign in with email and password

#

and then check firebase's api, and after that store their user ID in a cookie?

meager anchor
#

all the firebase jazz isn't of interest for the frontend, you do that on the backend, unless i don't understand what firebase is

#

the frontend just displays it

loud walrus
#

correct

#

but the backend is django?

#

aka python

#

aka actually logging in?

#

I just dont get the relationship between django and the actual html and css?

#

django handles the interactions, but that confuses me... lol

#

how does it know when the button is pressed or whatever?

#

I am more of a OpenGL man, so I dont really relate to any of this.

#
{% if messg %}
<script>
    alert('{{ messg }}');
</script>
#

oh I use javascript to check for relationships in the data?

#

srry I am kind of an idiot

#

like @meager anchor would it be possible to use Adobe DreamWeaver for the frontend actual html, and then use django for the backend?

meager anchor
#

no idea how dreamweaver works, i write my html myself

#

keep in mind that you'd work with django templates though

deep cave
#

there is no support for the django template language, or jinja2 or mako in Dreamweaver.

#

so it's a terrible choice.

#

it would be theoretically possible, but not practical

brave mantle
#

Forget dreamweaver

#

Forget pretty much anything that writes html for you to be honest

#

You should just learn html

deep cave
#

yep

#

it's not complicated

brave mantle
#

I hear htmldog is pretty good

jade rapids
#

i saw some of sentdex django tutorial and there while explaining about {% block content %} {% endblock %} , he said its ginger logic, but i dont really get what is this logic

#

can somebody explain me what exactly is ginger logic?

grand badge
#

not ginger, jinja

#

also, django by default doesnt use jinja2 syntax

teal mural
#

^

grand badge
#

its just similiar to jinja

#

@jade rapids when we talk about logic in templates, we are talking about added functionality in templates that you cant achieve with just html

#

anything that starts with {% and ends with %} is logic

jade rapids
#

oh thank you

#

now its more clear and i feel more dumb lol

grand badge
#

for example

{% if not condition %}
    <h1>Some text</h1>
{% endif %}
#

you will only see the <h1> if the condition variable is false

#

you can translate this into python

if not condition:
    print('some text')
jade rapids
#

ohh okie

#

so we can write any logic between {% %} ?

grand badge
#

yes

#

remember, logic must always be closed, like variables

#
{% block content %}
{% endblock %}
jade rapids
#

are there variables also in jinja?

grand badge
#

there is

#

but in django, the default isnt jinja

#

they work the same way

#

{{ variable }}

#

but some syntax is different

jade rapids
#

do i need to learn jinja first for understanding django?

grand badge
#

no

jade rapids
#

okie

grand badge
#

you can learn django templates

jade rapids
#

can u recommend me some good resources for django?

grand badge
#

sentdex has a good tutorial, but thats in 1.11

#

pretty printed makes abit more advanced vids in django

jade rapids
#

ohkie thanks

grand badge
#

he is good

jade rapids
#

i will see that GWnanaPepoHype

grand badge
jade rapids
#

hmm

polar robin
#

traversy just reads docs out for you

modern acorn
#

so i'm debating about going for flask or django as a starting point for web development

#

django looks more interesting though

brittle copper
#

Both are great frameworks

desert ingot
#

^

#

it depends on what you're trying to build

#

for most webapps i'd say django

#

flask for other projects where you'd want to have more controol

modern acorn
#

I honestly dont know

#

I just want to create feature rich websites, and perhaps make a small social media website or something just for practise

#

I'm just interested to get into back-end development

brittle copper
#

Doesn't really matter, the difference is django has lots of stuff built-in

#

And Flask doesn't

#

If you are okay with using the built-in go with django

#

If you want to use your own stuff, go with flask and choose it

modern acorn
#

I'm just more concerned if using django will hold me back when it comes to gaining knowledge

brittle copper
#

Knowledge about what?

modern acorn
#

web development and python in general

brittle copper
#

You should already know python in general to dive into a framework

modern acorn
#

I do lol

#

I've just learned the basics of the language, and I'm trying to dive into a framework

brittle copper
#

How basics

modern acorn
#

Things you would learn from going through a book

#

I've only done low-level stuff in the past in C, but this is the first time im diving into more abstract languages and trying to develop software

brittle copper
#

If you already know deque, collections, socket, itertools, and etc

#

And if you can use them

#

Those are just literally random libraries I pulled out of my ass by the way

#

If you know what classes are etc and etc

#

You are good to go

#

You can just pick django if you want batteries included and flask if not

#

There is nothing in there that will teach you python anyway, it is just a whole new world called web dev

#

using django will hold me back when it comes to gaining knowledge

#

I mean django offers a ORM for database for instance built-in

#

But you can just choose not to use it

#

Django offers a built-in user model that you don't have to use

#

Django offers an administration page you can opt-out

#

If you want to learn how to use databases especially for instance you can go with flask to learn how to integrate your project with a database

modern acorn
#

thanks

grand badge
#

Could anyone suggest me some good resources on Django's testing framework?

meager anchor
#

the docs worked pretty well for me

#

what's wrong with those?

buoyant ledge
#

Setting up a django / uwsgi server running on nginx. I have it (fully) setup, I think, but the web server tells me 502 bad gateway on every request now. any ideas?

#

not sure which config files / dir structures are relevant to paste

buoyant ledge
#

ik it's not strictly Python related just not sure where else to ask. been pounding away at it all day

acoustic river
#

does your nginx error log say anything?

buoyant ledge
#

It did. finally got it working, completely destroyed the setup for like the 4th time, reinstalled, etc followed tutorial again and it works now

sage wedge
#

hi

#

im trying to make a sqlalchemy query from within a flask wtform class

#
from flask_wtf import FlaskForm
from wtforms import SubmitField, SelectField, SelectMultipleField
from wtforms.validators import Optional
from components.models import Course


class ProfileForm(FlaskForm):
    grade = SelectField('Grade', choices=[(9, 'Freshman'), (10, 'Sophomore'), (11, 'Junior'), (12, 'Senior')],
                        validators=[Optional()])
    valid_courses = Course.query.all()
    courses = SelectMultipleField('Courses', choices=[(course.name, course.id) for course in valid_courses], validators=[Optional()])
    submit = SubmitField('Update')
#

@meager anchor hi

#

im confused because it seems like theres no issue when i run a query in a custom validator in another component's form

#
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, SelectMultipleField
from wtforms.validators import DataRequired, EqualTo, ValidationError
from components.models import Student


class LoginForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    remember_me = BooleanField('Remember Me')
    submit = SubmitField('Sign In')


class RegistrationForm(FlaskForm):
    name = StringField('Name', validators=[DataRequired()])
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    password_confirmation = PasswordField('Confirm Password',
                                          validators=[DataRequired(), EqualTo('password')])
    grade = SelectField('Grade', choices=[(9, 'Freshman'), (10, 'Sophomore'), (11, 'Junior'), (12, 'Senior')], validators=[DataRequired()])
    submit = SubmitField('Register')

    def validate_username(self, username):
        user = Student.query.filter_by(username=username.data).first()
        if user is not None:
            raise ValidationError('Please use a different username')

meager anchor
#

i don't know flask, sorry

sage wedge
#

culol

#

i can't really dynamically generate the form it seems

#

do you think joseph knows

meager anchor
#

possibly

sage wedge
#

nvm

#

found it

meager anchor
#

👍

unborn terrace
#

Does anyone know why, in Django/DRF posting data from rest_framework.test.RequestsClient object results in data getting received as QueryDict without keeping data's nature, i.e.

# in my test
data = {'foo': [1, 2, 3]}
client.post(url, data)

# in my view
print(request.data)
# prints {'foo': ['1', '2', '3']}, as you can see 1, 2, 3 got converted to strings, why?

And finally, how can I enforce data's nature to be kept as original?

unborn terrace
#

Found solution, using the json named argument instead of data, like this:

client.post(url, json=data)
olive wharf
#

What a good way to get started with django/flask and which should i choose

native tide
#

depends on what you need

olive wharf
#

Something to tinker with to get familiar with the concepts

#

Theres no need other than self improvement

native tide
#

Both are great. I don't think there's the right answer here.

#

official tutorials should get you on your way

olive wharf
#

What are the key differences between the libs then?

native tide
#

django does more for you out of the box

#

Flask is more flexible

olive wharf
#

Hm

#

Welp, might as well just try both then

#

See what I like the best

native tide
#

if you aren't under time constraints, that seems like a good idea :)

olive wharf
#

I got all summer FeelsWinkMan

native tide
#

also don't pay too much attention to flask being a "micro" framework

#

it doesn't mean it's not suitable for large projects

#

but it does take a bit more work

#

and the default environment supports only one request at once afaik

#

on flask

#

aren't Django and Flask both synchronous?

dense shoal
#

@olive wharf i've started doing this tutorial by miguelgrinberg for flask

#

I am upto chapter 8 and i love it

#

watch the video to get a rough idea of what the tutorial entails

olive wharf
#

I decided to start out with django, but ill bookmark it for future use. However I'll most likely sit through Corey schafers vid series on flask first, mostly because i like his work

dense shoal
#

oh yeah that guy, i have him subscribed aswell

#

but reddit seems to love miguel grinberg's tutorial

#

but its not a video-based tutorial like corey schafers

olive wharf
#

All about preference ¯_(ツ)_/¯

#

Ill for sure read it when i get to flask though, so thanks for the link

dense shoal
#

yeah nah corey schafers stuff are just as good

#

no worries enjoy your summer

olive wharf
#

You too dblSmile

dense shoal
#

i'll be sure to enjoy our very wet winter over here pepe

rancid axle
#

anyone know of a good way to do memory profiling for a flask application?

last blaze
#

how do grid templates work? o.o

native tide
#

May I ask a question @last blaze ?

last blaze
#

She

native tide
#

she?

#

like I mean my own, about web-dev I have no I dea how grid templates work

#

hey boys, I'm still using flask and when you render a template and send a variable along with it
return render_template("MyPage.html", MyList = [Bunch of string])

whenever this get's parsed in the js code
var MyArray = {{ title }}

jinja2 automatically escapes the apostrophes
so for example the list [ 'memes', 'dreams'] in python transfered to JS becomes [&#39memes&#39, &#39dreams&#39]

I already tried to add safe in the html file
so when I take the python array it doesn't automatically turn them into those hex codes

var Myarray = {{ title | safe }}

yet I still get these escape codes in my JS array, when I take at look through dev tools
if anyone knows how to solve this please DM me.
I have also tried

import jinja2
MyList = [ Bunch of strings]
render_template("MyPage.html",Mylist = jinja2.escape(MyList)

still doesn't work

deep prism
#

@native tide
Nothing special needs to be done. Are you sure that your MyList is truly just a list of strings?

native tide
#

well I think it's a list of strings

#

[('text', 6.400466379878729), ('rdata',5.6693643070101585), ('data', 2.0677782640502413), ('pdata', 5.873699144062637), ('didat', 0.8050372616935684), ('CPADinfo', 0.12227588125913882), ('rsrc', 6.932746768002647), ('reloc', 5.36807357956736)]

#

and then on the html page in the javascript part the variable has the ' in it which gets escaped to &#39

#

@deep prism

deep prism
#

ah okay, it's mostly about the javascript bit then.

native tide
#

yeah but I thought it's most appropriate to post here because there ar e apparently python solutions to this through flask

deep prism
#

It's strange that your |safe didn't work, because that should be the solution.

native tide
#
<script>
    

    var ctx = document.getElementById("MyChart").getContext('2d');
    var Titles = {{ title }}
    var Entropy = {{ entropy }}
    var ActualColour = []
    var borderFolor = []
    function getRandomRgba() {
        var num = Math.round(0xffffff * Math.random());
        var r = num >> 16;
        var g = num >> 8 & 255;
        var b = num & 255;
        var a = 0.2;
        return 'rgba(' + r + ', ' + g + ', ' + b + ',' + a + ')';
    }
    function getRandomRgbo() {
        var num = Math.round(0xffffff * Math.random());
        var r = num >> 16;
        var g = num >> 8 & 255;
        var b = num & 255;
        var a = 1;
        return 'rgba(' + r + ', ' + g + ', ' + b + ',' + a + ')';
    }
    var Titles = {{ title|safe }};
    var Entropy = {{ entropy|safe }}
    for (i = 0; i < Entropy.length; i++) {
        ActualColour.push(getRandomRgba())
    }
    for (i = 0; i < Entropy.length; i++) {
        borderFolor.push(getRandomRgbo())
    }
  
    var myChart = new Chart(ctx, {
            type: 'bar',
            data: {
                labels: Titles.clone(),
                datasets: [{
                    label: 'Entropy',
                    data = Entropy.clone()   ,
                    backgroundColor: graphColors ,
                    borderColor = graphOutlines ,
                    borderWidth: 1
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: true
                        }
                    }]
                }
            }
        });

    
   

</script>
#

it should work here correct

deep prism
#

It should, the only difference i have is that i used type=text/javascript

#

I'll try without

#

nah, same thing. Just works with safe

native tide
#

don't forget to do Shift+f5

#

because your page is still cached

#

I do it everytime just incase

deep prism
#
<!doctype html>
<html>
   <body>
       <script>
           safe= [('text', 6.400466379878729), ('rdata', 5.6693643070101585), ('data', 2.0677782640502413), ('pdata', 5.873699144062637), ('didat', 0.8050372616935684), ('CPADinfo', 0.12227588125913882), ('rsrc', 6.932746768002647), ('reloc', 5.36807357956736)];
           not_safe = [(&#39;text&#39;, 6.400466379878729), (&#39;rdata&#39;, 5.6693643070101585), (&#39;data&#39;, 2.0677782640502413), (&#39;pdata&#39;, 5.873699144062637), (&#39;didat&#39;, 0.8050372616935684), (&#39;CPADinfo&#39;, 0.12227588125913882), (&#39;rsrc&#39;, 6.932746768002647), (&#39;reloc&#39;, 5.36807357956736)];
       </script>
   </body>
</html>
native tide
#

maybe it's because my string was a byte object that I decoded

deep prism
#

Don't forget in the code you posted you have another var Titles = {{ title }} on top, 2nd line

native tide
#

Sorry I'm confused, I don't see a seond var TItles

#

that was just example code, my first post this code I posted is all of it

deep prism
#

I don't see that first code you posted then..

native tide
#

wait sorry let me clarify

#

my code is just the one I posted right now the JS

#

everything else is an example

deep prism
#

Well the first 2 variables are not |safe

var ctx = document.getElementById("MyChart").getContext('2d');
    var Titles = {{ title }} // <-- this
    var Entropy = {{ entropy }}   // <-- this
    var ActualColour = []
    var borderFolor = []

And a couple of lines below that you declare them again with safe

native tide
#

ah yeah I just took that off lemme put it back on, my bad

#

ey it works

#

turns out you just cant have a space after the |

#

which I had previously , Thanks! @deep prism

deep prism
#

spaces don't matter there though. It must've been something else.

native tide
#

I have no clue what it was then

#

but it works

native tide
#

Another question

#

sometimes when I upload it works

#

sometimes when I upload I get doubleslashes behind my dir and it tells me this

#

here is my PyCode

@app.route('/', methods=['POST'])
def upload_file():
    print(request.method)
    if request.method == 'POST':
        # check if the post request has the file part
        if 'filepond' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['filepond']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No selected file')
            print("part2")
            return redirect(request.url)
        if file:
            filename = secure_filename(file.filename)
            if not os.path.isdir(os.path.join(app.config['UPLOAD_FOLDER'], filename)) != False:    
                file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            MyDict = {}
            MyDict = PyDetect.MethMain(os.path.join(app.config['UPLOAD_FOLDER'],filename),MyDict)
            session['FilePath'] = os.path.join(app.config['UPLOAD_FOLDER'],filename)
            return redirect('http://localhost:5000/Results')
#

by the way yes discord formatting sux

#

app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

#

UPLOAD_FOLDER = 'uploads'

deep prism
#

when you say it sometimes works and sometimes it doesn.t is that with different files or the same one always?

native tide
#

depends

#

it's usually when I pick the same file in a session more than once

#

@deep prism just tested

#

it's when you pick after a session

#

when you pick the same file more that one time a session

#

a session being a restart of the flask server

deep prism
#

where does it fail btw, it's in the file.save right?

native tide
#

yeah

supple barn
#

if not os.path.isdir(os.path.join(app.config['UPLOAD_FOLDER'], filename)) != False:

#

what is this supposed to do?

#

filename will never be a dir

#

do you maybe want to check os.path.exists or os.path.isfile instead?

#

and why the double... or triple negation?

native tide
#

yes

supple barn
#

I would simplify that if for now

native tide
#

os.path.exists

supple barn
#

so

native tide
#

that's what I'm gonna use

supple barn
#

if not os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], filename)):

#

there's no need for the != False

native tide
#

yeah I know it's like C syntax, but I doubt my self other wise

supple barn
#

Putting it is just confusing

#

don't

#

because you put it there initially it probably also failed

#

because you mixed up your negations

native tide
#

nah I put a print there and it worked

deep prism
#

yea, not not-equals is very confusing.
either way, your code works just fine for me.

native tide
#

everytime?

supple barn
#

It worked in strange cases then, because you were checking for isdir from the beginning

deep prism
#

yea, every time

#

I didnt do that secure file though...

#

probably should

native tide
#

works perfectly now

#

it was that isdir

#

so it's os.path.exists thanks

supple barn
#

fix your negations

#

I know you think it's ok, but writing C code in Python is not really

#

for anyone else reading your code

native tide
#

it was that one thing, and I know it wasn't good

#

I just wasnt sure

#

most of my code is python like

#

no worries 😃

supple barn
#

great 😃

deep prism
#

it makes no sense though. that isdir thing is just an if-statement. it doesn't change variables, it shouldn't have any effect on the error you had.

native tide
#

I know

#

it makes no fucking sense

supple barn
#

well

#

you checked if a file that existed was a directory

#

that will always be false

brittle copper
#

It is an os error tho

supple barn
#

so file.save tried to overwrite an existing file

#

maybe that raised the error?

native tide
#

this is the line on which it errored
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

supple barn
#

what was the exact error again?

#

ah I see

native tide
supple barn
#

well

#

I think it uses shutil internally

#

the file.save

#

and it tried to move/copy a file where one already was

#

and raised an OSError

#

it does that for some functions

deep prism
#

where does a double backslash come from though.

native tide
#

I don't know

supple barn
#

the double slashback is there because he is using it on Windows

native tide
#

yeah

supple barn
#

and they used repr()

deep prism
#

I know os.path.join will make a double backslash if the filename has a backslash, but why would filename have that

supple barn
#

to display the error

#

pretty sure at least

#
user@host ~ $ print('a\\test')
a\test
user@host ~ $ print(repr('a\\test'))
'a\\test'
#

so the exception text was repr(path) that failed

native tide
#

I already tried 50 file uploads

#

but lemme check again

supple barn
#

it failed before because shutil (most likely) tried to move/copy/save a file onto an existing file

#

probably from a /tmp dir

#

because you checked isdir on an existing path

#

always causing the save.file to be triggered

deep prism
#

the file.save is fine for overwriting files though

#

unless of course it's in use or something prevents it.

supple barn
#

Are you sure about that? This seems to imply differently

#

do you have the full traceback @native tide ?

#

it would even make sense to not just allow overwrites if it's part of flask or whatever

#

because that could be easily exploited

native tide
#

yes I do

supple barn
#

can you post it?

native tide
#

not anymore since the problem is resolved

#

it's not in the console since I restarted the server

supple barn
#

hm seems correct, that it should have been overwritten. No idea then

#

oh well

deep prism
#

I changed permission on my file to overwrite and it gives me PermissionError: [Errno 13] Permission denied: '/tmp/uploads/test.html'
So the OS would probably give a more clearer error than just "invalid argument" if it were in use, or invalid permissions.

#

Idk why it's just "invalid argument", it has to be because of that backslash stuff

supple barn
#
C:\test\test.txt
user@host ~ $ print(repr(my_path))
'C:\\test\\test.txt'
user@host ~ $ 

#

again, the double backslashes are part of the repr representation of a string

#

which is used in the raised exception

#

the actual string does not have 2 backslashes

#

they are just escaped so you know that the escape sequence \t isn't meant

deep prism
#

What other "arguments" can there be though

supple barn
#

ok wait.

#

this is what happens

#

only if you actually have a tab-escape sequence \t

#

will repr show \ without an escaping \\

#

the argument was that he attempted to save a file where one already was, and something failed.

native tide
#

that actually makes sense

deft star
#

Is it easier to use wget / curl to pull html pages with bash or should I just result to beautiful soup?

#

and is there a way to just read an html file as a text file or is there encoding/decoding that needs to happen? Not really familiar with file encoding types

sour heath
#

so, how do people make a photo a button, like in cards? Such as binding a function to the card being clicked

buoyant ledge
#

There’s an onclick event you can add inside image tags or add an event listener directly to the ID

sour heath
#

within flask?

#

@buoyant ledge

buoyant ledge
#

You’d do it on the html side

sour heath
#

like in my template?

buoyant ledge
#

Yeah. That should work. I don’t know the exact implementation in flask but that’s how it’s done in traditional setups

#

And the html should work the same

sour heath
#

also, how could I set up a sort of 'game' between two people, what systems do people usually use to do something like that?

wary mantle
#

why does it give me that error and it doesn't load anything up

#

i have index.html in the same folder

rigid stratus
#

uh

#

make a folder called templates and put the index.html there bud

wary mantle
#

oh... ok..i get it now.

#

thanks

#

👍

rigid stratus
#

👌 @wary mantle np m8

wary mantle
#

😄

#

thanks

sour heath
#

how can I display an image in flask given the image path?

strange thorn
#

You cant Display stuff with flask?

sour heath
#

well, how can I put an image into the html

deep cave
#

with an <img> tag?

sour heath
#

well, yeah, but I'm using the path of the image as my 'src' and it doesn't appear to be working

#

I could be wrong about what I'm supposed to use

pearl geyser
#
  • Are you sure that the image exists?
  • Where are you putting this <img> tag
sour heath
#

I'm sure it exists as the path is copied from the image itself

#

and using it in my file directory brings the image

#

by where I'm putting it what do you mean?

pearl geyser
#

Hmm, could you post the whole <img> tag?

sour heath
#

<img src='{0}' filename='img.png' width=100 />

#

C:/Users/myusername/PycharmProjects/Project/playing cards/jack_of_diamonds.png is formatted

pearl geyser
#

That should work 🤔

sour heath
#

yea, I know

pearl geyser
#

you could view source and see if the image tag is coming out okay

sour heath
#

like inspect element?

pearl geyser
#

nah I mean just view source and see if the image tag is properly formatted but yeah you could do that with inspect too

sour heath
#

opening the image in a new tab return 404

#

might have found an issue

#

127.0.0.1 - - [29/Jun/2018 17:17:54] "GET /static/2_of_spades.png HTTP/1.1" 404 -
127.0.0.1 - - [29/Jun/2018 17:17:54] "GET /favicon.ico HTTP/1.1" 404 -

#

it has to be something with my static directory

wary mantle
dense slate
#

You could line break right after the form field before the submit button?

#

Or put the submit button in its own row/div.

sour heath
#

As I'm attempting to run a variable into an app route, I get an error: TypeError: end1() missing 2 required positional arguments: 'score1' and 'score2'
127.0.0.1 - - [30/Jun/2018 21:09:29] "GET /end1?score1=107&score2=121 HTTP/1.1" 500 -

#

I'm not sure why as I'm passing it through here: python return redirect(url_for('end', score2=p1score, score1=p2score))

meager anchor
#

Those are keyword arguments, not positional

zinc cypress
#

is correct to return 204 after a post request?

hearty birch
#

201

#

well, 204 could be used if there is no information to send back to the client

zinc cypress
#

yeah, a confirmation should be good

solemn pawn
#

is someone with a bit of experience with flask currently here?

brave mantle
#

Ask your question :P

solemn pawn
#

it outputs this exception in the console: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise raise value File "/usr/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) TypeError: receive_vote() missing 1 required positional argument: 'self'

brave mantle
#

You will not want to use flask for this

#

Right off the bat

#

You're implementing the webserver in the same program as your bot

solemn pawn
#

i've already tried web.py, didn't work well either

brave mantle
#

Yeah no, that won't work, because you need something that supports asyncio

#

You should be using aiohttp

solemn pawn
#

can i receive webhooks with aiohttp?

brave mantle
#

Yeah, it does the usual stuff

solemn pawn
#

okay, gonna look into that, thank you

brave mantle
#

You should consider whether this is really what you want though

#

Most of the time, the site and bot parts are separate apps

solemn pawn
#

i don't want to host a site

brave mantle
#

And then you have them communicate somehow, eg using rabbitmq

#

Well, you are, lol

solemn pawn
#

i know, but that's not my main purpose

#

the only thing this code should do is listen for incoming webhooks from Discord Bot List

#

and process them

brave mantle
#

Right, but either way, you need an http server

rugged abyss
supple barn
#

@finite bison your question is strange

#

oh

#

view-source: probably returns the unmodified DOM

#

whereas page_source returns the current DOM, modified by JavaScript

rugged abyss
#

Ah okay, is there a way to view the unmodified DOM through a selenium command?

keen ore
#

hmm, im making a register/login system with python, pyodbc and flask, how should i implement a "Confirm your email" functionality

wary mantle
#

hey.. so i want a button saying advanced, when the user clicks that, something appears. how can i do this with bootstrap ?

shrewd sand
#
  @media only screen and (max-zoom: 80%){
    .label {
      flex-direction: column
    }
  }

#

What is the correct way to write this?

#

I want it to go to a colum past a certain screen zoom

sour heath
#

How can I remove or move an image in flask, I want to have it where upon clicking an image, it will remove it

brittle copper
#

Removing it from ...

sour heath
#

an html template

#

to have it not appear on the page

#

<img src="{{url_for('static', filename=image_name)}}", width="50", onclick="removeimages()" />

#

like this

#

and have the function remove that image

#

I'm not sure if I have it right though

keen ore
#

hmm i have not done any frontend development before, but i do know javacript ,php, and html (css is my weakest skill) and i have almost no skills in mkaing things look nice and i need to make a responsive website, i'd sort of wanna do it with python.
i have made a api for the site with python and flask.
how should i proceed for the front end? django?

#

aand i have deadline in 4 weeks 😐

deep cave
#

no reason you can't continue using flask

#

if you've already got experience with it, it's probably not a bad choice

#

html and css will still be required to make it look nice no matter which framework you choose.

#

but you could use something like bootstrap or bulma to do the heavy lifting css for you

#

bulma is really nice.

#

with bulma, flask and some html you'd have a website looking pretty good in mere days.

#

as for responsive, that'll probably require either css or javascript to pull off - it's not gonna be possible to do with just python

#

but you said you knew js so that sounds like it won't be a problem.

dense slate
#

@wary mantle You can do this pretty easily with some javascript. Stackoverflow has a lot of good examples. Might not all be for bootstrap, but you can probably hack your way through their answers to just add a simple BS button.

unborn terrace
#

@keen ore Python has nothing to do with responsiveness, it is just used for backend

feral dragon
#

@gentle sapphire I made sure I broke the reverse proxy already by trying new stuff configuring it

#

For some reason my venv was Python2 instead of Python3 so I attempted to change it

idle osprey
#

for flask templates, where is the defult ./

#

i.e. i want ./script.js, where would flask find it

#

found out, it has to be in a static folder and to load it you have to use <script src="{{ url_for('static', filename='js/script.js') }}"></script>

who tf greenlighted this

feral dragon
#

Your filesystem would look like this @idle osprey /root/static/js/script.js/

#

Root being the root dir

#

Where your index is and your wsgi and app are located

feral dragon
#

Fixed

gentle sapphire
#

@feral dragon will be back in the AM

#

Chat you in the morning

feral dragon
#

I fixed it

#

No need

sour heath
#

Is there anything like a listbox from tkinter in html?

deep cave
#

no. but you could build a table and make each row clickable and you'd get close.

#

then add some buttons

#

might need a js event handler to make the table rows clickable though. but it's not hard to google a solution for.

#

(tags like <tr> don't like being wrapped in <a>s.)

sour heath
#

I just wanted something that I could add to based on a list

deep cave
#

are you using a python web framework?

#

in that case you can still build that

#

you just spit out that list when you render your template and then have a for loop in the table that makes a table row for each list item

cosmic dove
#

Does anyone mind if I pm them some questions regarding Django? I am googling most of them, however, I am not sure what a lot of the terms are.

brave mantle
#

bot.tags.get no-dm

lavish prismBOT
#
no-dm

Can I send you a private message?

No. We do not provide one-on-one tutoring - you can hire someone locally if you really need that. We also prefer that questions are answered in a public channel as it means that everyone else present is able to learn from them. If you're working with code that you are unable to disclose for any reason, you should try to make your question more general and write a separate, small piece of code to illustrate your problem.

grand badge
#

@cosmic dove ask your question

buoyant ledge
#

Speaking of Django when running uwsgi how do I deploy the full project. Like what file do I point it at?

native tide
#

point it at yourproject.wsgi

keen ore
#

hmmhow do i post a data from a form to flask without leaving the page and how do i display a text on that page depending in the response from my backend

compact lion
#

Ajax @keen ore

keen ore
#

Well, i mean sure, but should i return data to it from flask?

#

also, what about flask-wtf?

compact lion
#

No clue what that is but usually you use Ajax to query some endpoint on your flask app to get data you need and display it

hearty birch
#

I would use flask-wtforms

#

oops

#

a bit late

buoyant ledge
#

@native tide what does the .wsgi consist of?

gentle sapphire
#

it's a run file,

#

it runs the web app

#

so, mostly an import to call the app, and a main()

keen ore
#

can i make a form with "add field" functionality with flask_wtf? i want to have a form where users can add ass many skills as they want in a single go,sort of like this:

Skill name:[           ]
Skill level:  [           ]
add skill...
[Submit]
#

and clicking add skill makes it like this

Skill name:[           ]
Skill level:[           ]
 
Skill name:[           ]
Skill level:[           ]
add skill...
[Submit]
sour heath
#

so can someone explain how onclick works?

native tide
#

Does it have any connection with python?

sour heath
#

I want to be able to call a function upon clicking an image, correct me if I'm wrong but I think thats the main solution I should use

#

by that what do you mean?

native tide
#

This is a python server.

sour heath
#

the function being a python function

#

yes

native tide
#

Oh

#

ok

#

What do you mean by "how onclick works"?

sour heath
#

within html

native tide
#

Like this:

<button onclick="js action here">button</button>```
#

Example with button.

#

Same with img but you set the source.

sour heath
#

so why is it a js action?

native tide
#

Because that how HTML works.

kind steppe
#

You can't run Python in HTML @sour heath

#

@native tide This channel can be used for talking about HTML, CSS or JavaScript

sour heath
#

okay, thanks

native tide
#

Oh, ok. I wasn't sure.

kind steppe
#

JavaScript is used for scripting webpages, so a HTML element event will always trigger a JavaScript function

#

No problem

sour heath
#

and you can write the js within the html?

kind steppe
#

you can

#

So

#

example time ✨

#
<script>
function myFunction() {
    alert("You clicked the button!")
}
</script>

<button onclick="myFunction()">Click me!</button>
sour heath
#

so within the js, you can call python functions, which is the whole tie between them?

kind steppe
#

No

#

There is no tie between them

sour heath
#

oh

kind steppe
#

Python is nothing to do with frontend web development

sour heath
#

oh

kind steppe
#

There are various ways you can write "Python" in the browser, but I don't recommend any of them

sour heath
#

so trying to write a web program with python involved seems useless?

kind steppe
#

Yes

#

because you can't do it

#

you will either write python which gets converted into JS, or just end up using JS

sour heath
#

well, good to know

kind steppe
#

If you are looking to learn web dev, it is one of the things codecademy offers a relatively good course on, so I recommend that

sour heath
#

well, I'm using python

#

so I'm not sure

kind steppe
#

Python is a good skill for backend web dev

#

You may not be able to write the bit the user sees in Python, but you can certainly write the bit which sends the data to the user and processes requests in Python

sour heath
#

well, I don't think I could do it, I'll just have to convert to some gui

kind steppe
#

If you are looking into GUI's, I recommend looking at PySide2

sour heath
#

okay, thanks

kind steppe
sour heath
#

wait, were you suggesting I use flask?

#

because thats like, exactly what I've been using

kind steppe
#

I was saying python can be used on backend not front end

#

if you are already doing that then that is awesome :D

sour heath
#

well, I'm not sure

#

would buttons working be similar?

kind steppe
#

I'm really confused as to what you are asking about now

#

Flask is not a GUI framework

sour heath
#

yes, I know that

kind steppe
#

buttons would be similar yes

sour heath
#

great, so using get and post?

kind steppe
#

You could tie it in using something like requests, yes

sour heath
#

using onclick?

kind steppe
#

Not exactly onclick, because it is not HTML

sour heath
#

oh

sour heath
#

is this the gui again?

kind steppe
#

and then we connect the button to a say_hello function

#

Yes, this is pyside2

#

In fact

keen ore
#

how do i make a existing form on website work properly with flask-wtf form?

meager anchor
#

we're gonna need more information than that

keen ore
#

nevermind, i figured it out 😃

#

but, now i need to figure out how i can make my page fill the screen and not leave a white void under footer on empty pages

keen ore
#

how can i makee the footer stick to the bottom of the page even when there is no content above it

#

with position: fixed it stays at bottom of the screen and covers any content

quick scarab
#

anyone ideas why my css works in ie but not chrome?

keen ore
#

reload with shift f5

#

chrome caches css

quick scarab
#

yeah, tried that, no luck

keen ore
#

can you post your css?

quick scarab
#
#container {
    background-color: #ff6600;
}
p {
    color: white;
}
#

pretty simple stuff lmao

keen ore
#

what part is not working?

keen ore
#

html?

quick scarab
#
<!DOCTYPE html>
<html>
<head>
    <title>Home Page</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    <link  rel="stylesheet" type="text/css" href="{{ url_for('static', filename='homepagestyle.css') }}">
</head>
<body>

    <div class="container" id="wrapper">
            <p id="loginforminfo"> Login to continue to the site: </p>

    </div>
</body>
</html>
keen ore
#

hmm

#
<p class="infobox">

and

.infobox{
    background-color: #ff6600;
}
#

or replace #container with .container

quick scarab
#

no luck 😭

keen ore
#

hmm

quick scarab
#

tried changing the href to a static one, didn't work

keen ore
#
.container {
    background-color: #ff6600 !important; 
}
p {
    color: white;
}