Instance of 'dict' has no 'replace' member

2019-02-01 Thread sinless199
Hello guys can you help me to solve problem when i compile proram got error 
like this "Instance of 'dict' has no 'replace' member[no member](67;14)".
here you can see my code.
url = "http://mapa.um.warszawa.pl/mapviewer/foi";
querystring = 
{"request":"getfoi","version":"1.0","bbox":"${xmin}:${ymin}:${xmax}:${ymax}","width":"${imageWidth}","height":"${imageHeight}","theme":"dane_wawa.NMZ_WUP_WODA","clickable":"no","area":"yes","dstsrid":"2178","wholeimage":"yes","renderlabels":"yes","tid":"653_1461267","aw":"no"}
payload = ""
headers = {
'cache-control': "no-cache",
'Postman-Token': "d23cc8e3-423e-43a0-9d54-0cae251a4de9"
}




if not os.path.exists(targetDir):
os.makedirs(targetDir)
##
# Main loop ##
##
for y in range(fullExtent['ymax'], fullExtent['ymin'], - tileSizeY):
for x in range(fullExtent['xmin'], fullExtent['xmax'], tileSizeX):
targetFile = open(targetDir + "\\" + str(x) + "_" + str(y) + 
".png", "wb")
url_link = querystring.replace("${ymin}", str(y - 
tileSizeY)).replace("${xmin}", str(x)).replace("${xmax}", str(x + 
tileSizeX)).replace("${ymax}", str(y)).replace("${imageWidth}", 
str(imageWidth)).replace("${imageHeight}",str(imageHeight))
targetWorldFile = open(targetDir + "\\" + str(x) + "_" + str(y) 
+ ".pgw", "w")
print ("URL: " + url + "\n")
for tryNum in range(0, retryTimes):
try:
response_get = requests.get(url, data=payload, headers=headers, 
 params=url_link)
req = urllib2.Request(response_get.text[66:131], None, 
{'User-Agent': userAgentString})
response = urllib2.urlopen(req)
responseText = response.read()
targetFile.write(responseText)
targetWorldFile.write(str(pixelSizeX) + "\n" + str(0.000) + 
"\n" + str(0.000)+ "\n" + str(-pixelSizeY) + "\n" + str(y - tileSizeY) + 
"\n" + str(x + tileSizeX))
except Exception:
img = Image.new('RGBA', (imageWidth, imageHeight))
img.save(targetFile)
pass
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Instance of 'dict' has no 'replace' member

2019-02-01 Thread Dan Sommers

On 2/1/19 7:15 AM, sinless...@gmail.com wrote:

Hello guys can you help me to solve problem when i compile proram got error like this 
"Instance of 'dict' has no 'replace' member[no member](67;14)".


Python dicts don't have a replace method.

It looks like you're trying to replace strings inside particular
dict entries; perhaps you meant something like this:

querystring["key"] =
querystring["key"].replace("placeholder", "value")

HTH,
Dan
--
https://mail.python.org/mailman/listinfo/python-list


OT - need help with PHP

2019-02-01 Thread Bob Gailer
Trying to setup PHP on Windows 10  using the curl extension to run
standalone. Why? I am trying to use an API where the only coding examples
are written in PHP. My goal is to use python, and the place where I'm stuck
is: the examples use Curl to post requests; my attempts to translate this
to urllib. request have failed.

I can't even figure out how to sign up for a PHP email list.

Help with either of the above would be welcome.

Bob Gailer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT - need help with PHP

2019-02-01 Thread Chris Angelico
On Sat, Feb 2, 2019 at 2:31 AM Bob Gailer  wrote:
>
> Trying to setup PHP on Windows 10  using the curl extension to run
> standalone. Why? I am trying to use an API where the only coding examples
> are written in PHP. My goal is to use python, and the place where I'm stuck
> is: the examples use Curl to post requests; my attempts to translate this
> to urllib. request have failed.
>

If it's an HTTP-based API, it's probably easier to translate the
examples to use the 'requests' library than to first set up PHP and
then translate everything to urllib after that.

http://docs.python-requests.org/en/master/

Feel free to post questions here of the form "here's an example of
doing something in PHP - how can I do that in Python", as that would
be 100% on topic.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT - need help with PHP

2019-02-01 Thread Larry Martell
On Fri, Feb 1, 2019 at 10:30 AM Bob Gailer  wrote:
> I can't even figure out how to sign up for a PHP email list.

http://php.net/manual/en/faq.mailinglist.php
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT - need help with PHP

2019-02-01 Thread mm0fmf

On 01/02/2019 15:36, Chris Angelico wrote:

On Sat, Feb 2, 2019 at 2:31 AM Bob Gailer  wrote:


Trying to setup PHP on Windows 10  using the curl extension to run
standalone. Why? I am trying to use an API where the only coding examples
are written in PHP. My goal is to use python, and the place where I'm stuck
is: the examples use Curl to post requests; my attempts to translate this
to urllib. request have failed.



If it's an HTTP-based API, it's probably easier to translate the
examples to use the 'requests' library than to first set up PHP and
then translate everything to urllib after that.

http://docs.python-requests.org/en/master/

Feel free to post questions here of the form "here's an example of
doing something in PHP - how can I do that in Python", as that would
be 100% on topic.

ChrisA


+1 for using requests.
--
https://mail.python.org/mailman/listinfo/python-list


Re: OT - need help with PHP

2019-02-01 Thread bob gailer

Thank you for your various responses.  All helpful and encouraging.

RE mailing list: I followed the instructions at 
http://php.net/manual/en/faq.mailinglist.php.


I have had no response. Shouldn't I get something either welcoming me to 
the list or requesting a confirmation?


Here are the instructions from the api vendor: (somewhat lengthy)

HOW TO CALL A FUNCTION USING VOIP.MS REST/JSON API
The following samples show how to get all Servers Information from our 
database and how to select a specific Server for your display purposes.


Please Note:
- When using our REST/JSON API you need to send the Method to be used 
and the Required Parameters as part of the URL.

- By default the output Content-Type is "text/html".
- If you want the output Content-Type to be "application/json", add the 
following to your URL: &content_type=json


PHP - Using cURL GET - Sample Code

|$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); 
curl_setopt($ch, CURLOPT_URL, 
"https://voip.ms/api/v1/rest.php?api_username=j...@domain.com&api_password=password&method=getServersInfo&server_pop=1";); 
$result1 = curl_exec($ch); curl_close($ch); 
$data1=json_decode($result1,true); print_r($data1);|



PHP - Using cURL POST - Sample Code

|$postfields = array( 'api_username'=>'j...@domain.com', 
'api_password'=>'password', 'method'=>'getServersInfo', 
'server_pop'=>'1'); $ch = curl_init(); curl_setopt($ch, 
CURLOPT_RETURNTRANSFER, true ); curl_setopt($ch, CURLOPT_POST, true ); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, 
CURLOPT_URL, "https://voip.ms/api/v1/rest.php";); $result = 
curl_exec($ch); curl_close($ch); $data=json_decode($result,true); 
print_r($data); |


Note: I have edited these examples by removing unnecessary stuff, to 
make their size reasonable.


On the Python side, I can make the GET version work using 
urllib.request. I will try requests soon.


When I try to run the post example using php -r "path-to-php-progran"; 
It just prints the program.


Any attempt at converting that to POST get me a Bad Request response.

One of my needs is to upload a .wav file. The vendor requires the file 
to be encoded into base64  and the result string included in the POST 
data, which can lead to enormously long POST data. I can successfully 
use GET to send very short .wav files, but the url length limit is 
quickly reached for a reasonable length recording. Trying to use the 
POST ability that allows me to specify the file by path fails at the 
vendor side.


Apology for long post, but I don't know what to omit. Again any help is 
welcome.


--
Bob Gailer


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
https://mail.python.org/mailman/listinfo/python-list


Re: OT - need help with PHP

2019-02-01 Thread Chris Angelico
On Sat, Feb 2, 2019 at 7:08 AM bob gailer  wrote:
> HOW TO CALL A FUNCTION USING VOIP.MS REST/JSON API
> The following samples show how to get all Servers Information from our
> database and how to select a specific Server for your display purposes.
>
> Please Note:
> - When using our REST/JSON API you need to send the Method to be used
> and the Required Parameters as part of the URL.
> - By default the output Content-Type is "text/html".
> - If you want the output Content-Type to be "application/json", add the
> following to your URL: &content_type=json

Cool, this is the most important information.

> PHP - Using cURL POST - Sample Code
>
> |$postfields = array( 'api_username'=>'j...@domain.com',
> 'api_password'=>'password', 'method'=>'getServersInfo',
> 'server_pop'=>'1'); $ch = curl_init(); curl_setopt($ch,
> CURLOPT_RETURNTRANSFER, true ); curl_setopt($ch, CURLOPT_POST, true );
> curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch,
> CURLOPT_URL, "https://voip.ms/api/v1/rest.php";); $result =
> curl_exec($ch); curl_close($ch); $data=json_decode($result,true);
> print_r($data); |

The PHP array can be converted easily into a Python dictionary:

postfields = {
"api_username": "j...@domain.com",
"api_password": "password",
"method": "getServersInfo",
"server_pop": "1",
}

I don't know what the CURLOPT_RETURNTRANSFER option does, so I'm going
to ignore it.

Since there's nothing obvious about the format of POST data, I'm going
to assume that it's meant to be form encoded. Give this a try and see
if it works.

r = requests.post("https://voip.ms/api/v1/rest.php";, data=postfields)

Many APIs use JSON rather than form encoding, in which case you'd say
"json=" instead of "data=", but that seems unlikely in this case.

> Note: I have edited these examples by removing unnecessary stuff, to
> make their size reasonable.

Assuming you haven't omitted anything important, the translation to
requests should be fairly straight-forward.

> One of my needs is to upload a .wav file. The vendor requires the file
> to be encoded into base64  and the result string included in the POST
> data, which can lead to enormously long POST data. I can successfully
> use GET to send very short .wav files, but the url length limit is
> quickly reached for a reasonable length recording. Trying to use the
> POST ability that allows me to specify the file by path fails at the
> vendor side.

http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file

You'd need to match the PHP examples to the way Requests does file
uploads, but it ought to work.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Selection based ob variables issue

2019-02-01 Thread vergos . nikolas
Hello, iam tryting to execute mysql queries based on python variables.



name = request.args.get('name')
month = request.args.get('month')
year = request.args.get('year')

try:
if '=' not in name + month + year:
cur.execute( '''SELECT * FROM jobs WHERE clientID = 
(SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, month, year) )
elif '=' not in name + year:
cur.execute( '''SELECT * FROM jobs WHERE clientID = 
(SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY 
lastvisit DESC''', (name, year) )
elif '=' not in month + year:
cur.execute( '''SELECT * FROM jobs WHERE 
MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', 
(month, year) )
elif '=' not in year:
cur.execute( '''SELECT * FROM jobs WHERE 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )
else:


Problem is that only the first clause works as expected and not the rest.
'=' means variables contains no value.

How can i make it work?
-- 
https://mail.python.org/mailman/listinfo/python-list